Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:31 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: On Key Escape fun and games

Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 02:58pm 26 Oct 2021
Copy link to clipboard 
Print this post

Noticed this in MMB4L and it's present on the CMM2 too:

> list "on_key_test.bas"
On Key 27, do_quit

Do
Loop

Sub do_quit
 End
End Sub


Run this and press one of the cursor keys, the program will end and display the remaining ANSI code for the cursor key without the leading escape character.

e.g. press [UP] and you get

[A


Possibly it's fixable, but might be simpler and not too limiting to add restrictions to valid ASCII codes for ON KEY ?

Best wishes,

Tom
Edited 2021-10-27 00:59 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 03:05pm 26 Oct 2021
Copy link to clipboard 
Print this post

  Quote  but might be simpler and not too limiting to add restrictions to valid ASCII codes for ON KEY ?


Doesn't need fixing IMHO - buyer beware

There are good reason why non-ascii are useful

OPTION BREAK 4
on key 3, tidyexit
sub tidyexit
' close things as required
option break 3
end sub
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 03:14pm 26 Oct 2021
Copy link to clipboard 
Print this post

  matherp said  
  Quote  but might be simpler and not too limiting to add restrictions to valid ASCII codes for ON KEY ?


Doesn't need fixing IMHO - buyer beware

There are good reason why non-ascii are useful

OPTION BREAK 4
on key 3, tidyexit
sub tidyexit
' close things as required
option break 3
end sub


Yes, I've done that myself on your suggestion, but ON KEY 27 is going to catch more than the [Escape] key and it screws up a bunch of other keys which is why I'm wondering if it either needs guarding against or handling better ... though the latter would be messy.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 04:35pm 26 Oct 2021
Copy link to clipboard 
Print this post

Not that I imagine you would change it, but is there a second use case for either ON KEY <code>, or OPTION BREAK <code>?

If not then couldn't they be replaced with ON BREAK ?

Best wishes,

Tom
Edited 2021-10-27 02:51 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 533
Posted: 06:06pm 26 Oct 2021
Copy link to clipboard 
Print this post

Hi Tom,
I'm using ON KEY 157, NCprintScreen for screenshots...
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 11:55pm 26 Oct 2021
Copy link to clipboard 
Print this post

I assume you are using a terminal program, not a connected keyboard.
the up arrow VT code is esc [ A so your program is working as programmed.
If you cater for terminal programs, you will have to wait for a time after the esc to see if any characters follow before treating it as escape alone.

Jim
VK7JH
MMedit
 
Goksteroo
Senior Member

Joined: 15/03/2021
Location: Australia
Posts: 114
Posted: 02:34am 27 Oct 2021
Copy link to clipboard 
Print this post

  jirsoft said  I'm using ON KEY 157, NCprintScreen for screenshots...

Why didn't I think of that - DOH!
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 10:06am 27 Oct 2021
Copy link to clipboard 
Print this post

  TassyJim said  I assume you are using a terminal program, not a connected keyboard.


Thanks Jim,

On the CMM2 "yes", and it doesn't usually happen if you use a USB keyboard ... though very occasionally I do seem to get it , presumably a timing thing.

On MMB4L the keyboard is connected, but MMBasic does run inside a local terminal and thus sees the VT codes rather than reading directly from the keyboard; MMB4L currently has no KEYDOWN function for this reason.

  Quote  the up arrow VT code is esc [ A so your program is working as programmed.
If you cater for terminal programs, you will have to wait for a time after the esc to see if any characters follow before treating it as escape alone.


Yes, I know, I understand, and that happens in the general keyboard input case, but MMB4L (like the CMM2) runs the code for intercepting/handling ON KEY <code> before the code that identifies and combines VT escape codes from the input into single bytes.

No action from anyone expected, just building up my knowledge.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025