Getting the key code

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Getting the key code

Post by richmond62 » Sun Feb 13, 2022 10:34 am

SShot 2022-02-13 at 11.32.09.png
-
This is NOT the same as the keyDown and keyUp value.

Is there a way to obtain the key code of a certain physical key inwith LiveCode?
-
800px-LibFig34-1.png

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Getting the key code

Post by dunbarx » Sun Feb 13, 2022 6:16 pm

Richmond.

I did not know that there was such a mapping. Where is it discussed, or defined?

Anyway, you can roll your own. It merely requires that you create a table that has the rawKeyDown-to-yourNewKeyCode correspondence. You also need to check such things as the "commandKeyDown", "optionKeyDown", etc.

Anyway, should only take half an hour to build.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the key code

Post by richmond62 » Sun Feb 13, 2022 6:56 pm

Anyway, you can roll your own.
Doubtful: I smoke a pipe. 8)
-
keyboardCrud.gif
-
Reading around (and round and round in ever-decreasing circles) I get the impression
that these re the codes that the physical keyboard sends down the wire to the computer.

Mind you, an internet search yields lots and lots of images, and in each one the numbers differ.

The ghost of Steve Jobs must be laughing his spectral socks off.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Getting the key code

Post by dunbarx » Sun Feb 13, 2022 11:24 pm

Richmond.

Then where did you get the idea that such codes exist in the first place?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the key code

Post by richmond62 » Mon Feb 14, 2022 7:37 am

Reading the Danny Goodman book and an idle web search for MacOS & key codes left me thoroughly confused.

Messing around with HyperCard on a PPC Mac Mini running emulated Mac OS 9 ('Classic') on Mac OS 10.4 does give a confusing
message. If I find the time today I shall run the same code in RunRev 1.1. on Classic as well to see, well, whatever I see. 8)
-
keysDown.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the key code

Post by richmond62 » Mon Feb 14, 2022 12:24 pm

RR&HC.jpg
-
Here are RunRev 1.1 and HyperCard 2.4.1 next to each other . . .

RunRev to the left, HC to the right.

What is clear is that Hypercard returns values for buttons such as Forward delete, while
RunRev does not.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Getting the key code

Post by dunbarx » Mon Feb 14, 2022 5:32 pm

Richmond.'

LC does return a value for the two different "deletes". 65535 and 65288.

Only the five "control" keys do not seem to have a value assigned to them. You must use either the "keysDown" function or trap their individual messages of individual functions to know if they are in play.

Craig

PaulDaMacMan
Posts: 627
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Getting the key code

Post by PaulDaMacMan » Sat Jan 13, 2024 7:46 pm

I'm pretty sure the rawKeyCodes enums list was set up way back when in the 1990s and, since MetaCard was a HyperCard clone, I'm guessing they were probably set to match HyperCard/classic macOS Roman character set, which BTW included some non-standard char that were actually used as tokens in HyperTalk (for example option-L ¬ for script line continuation / soft-return, the equivalent of the backslash used in a script in LiveCode, also the Not-Equal character ≠ was the equivalent of "<>" in LCS).

The numbers returned don't seem to match the numbers I see when I look up modern macOS (NeXT/OS X) keycodes beyond maybe the lower 256 or 127 ASCII chars. All modifier keys do have rawKey char codes except for capsLock() so you need to check that seperately. Option/Alt, Option/Alt+Shift and Alt-Combo Characters on windows are the ones above single byte ASCII, so to key all codes you need to check the output of those too. To track all key-combos you can set up up 3 or 4 arrays, one set for lower case, one for upper-case, one for option-shift, and control-option-shift, and check against the appropriate list based on a check for any modifiers down and it's pretty fast.Then there's the functionKeys (and key-combo Fn keys too), arrowkeys, and extended keyboard numPad keys, and mediaKeys (on macOS those are used by the OS and not directly available to apps).
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”