There is no relationship between a key and a keycode.
You do not seems to know what is a keycode.
Try to read wikipedia: Keycode - Wikipedia
When was the last time you develop an application ?
There is no relationship between a key and a keycode.
You do not seems to know what is a keycode.
Try to read wikipedia: Keycode - Wikipedia
When was the last time you develop an application ?
Keyboard.AsyncKeyDown(keycode) answers the question, “Is this key currently being held down?” The way to determine which key(s) are being held down is to loop through all the possible keycodes and record which ones return True.
The Keyboard.Keyname function appears to solve the problem of having to know the keyboard layout.
var n as integer
var s as string
for n = 0 to 127
if Keyboard.AsyncKeyDown(n) then
s = Keyboard.Keyname(s)
if s = "Up" then
elseif s = "Left" then
end
end
next
Emile, let’s keep it civil. It is very clear Alexandre knows the difference. I think Keyname() is the missing piece.
@Tim_Hare
Don’t think @Emile_Schwarz was meaning to be rude in any way.
Emile just speaks in a certain tone and for anyone here long enough knows it is special Emile post/reply ![]()
Sorry, I give up.
Maybe this?
KeyCode.zip (5.1 KB)
Those keys have names… Run some code with a print command and you can easily print them out to see… Usually something like LEFT_ARROW
Key names are more likely a Xojo under the hood thing than a system assigned thing. Could be wrong but the keyboard has no concept of key names.
YES!!! thank you very much!!!
that’s what i’m looking for.
thank you for your patience.
Alex
Hi Emile
If i’m here is because i have a problem to sove, or i don’t have enough knowledge to do it a.s.a.p.
If you, or anyone else, DON’T want to help because you think I’m so stupid it’s a waste of time, it’s simple: don’t waste your time trying to help me. Go do something more fun, like fishing, for example.
But don’t be rude. The people participating here, who genuinely want to help, will certainly be upset.
As I said before, I learned to program when I was 6 years old. Yes, 6. My father was already an IBM programmer, back in the punch card era.
I learned Assembler, Fortran, Cobol, BASIC… and continued learning other languages. I probably don’t know as much as you, but I’m not an idiot.
UNFORTUNATELY, my entire solid foundation was in not structured programming. With lines, using “go to”… Object orientation is still, for me, a seven-headed beast, quite ugly, angry, and hairy.
Anyway: If you don’t want to help, go fishing. Seriously, really. Don’t waste your time trying to help someone who knows less than you.
About your comment:
There is no relationship between a key and a keycode.
You do not seems to know what is a keycode.
The key and the keycode are intrinsically related, but they play complementary roles:
A key cannot exist without a keycode, because the keycode is what physically identifies the key’s position on the keyboard hardware.
A keycode would be meaningless without a key, because it needs an associated function or character to be useful to the user.
God bless you. Have a great Sunday.
Alex
ahaaa…
how to get the Function (F1, F2…) key codes?
and shift, control, option and command?
and the caps lock?
how to know if it’s pressed the LEFT command key or the RIGHT command key?
![]()
Same, they all have key names, even the num row and num pad have separate key names
I’ve never done it with Xojo but I did this with AppGameKit.
They all have names and codes and since the codes are sequential you can map them dynamically on startup.
Even keys like F20 that don’t exist have key names, weird I know.
Those never change: whatever the layout (language), they’ll be at the same location, thus having the same value.
Command=55
Shift=56
Caps lock=57
Option=58
Ctrl=59
By the way, I’ve always wondered why Xojo only provides Keyboard.AsyncKeyDown but not the sync version “Keyboard.KeyDown” (which would query the state from the original event, like it does for the other sync methods of CommandKey, OptionKey, ShiftKey and ControlKey). That’s actually what’s missing in the keyboard object.
They do. It’s called Key. The sync methods are only meaningful in KeyDown, where the Key itself is passed to you. So the sync versions only have to report the state of the modifier keys. Sync = KeyDown event. Async = everywhere else (usually a Timer).
thank you!
2 more questions:
Fn and F1, F2, etc?
Did you get this by code?
you call asc(string) to get the integer ascii code for the passed in string from key down event. I think that is what you have been wanting. That’s how I trap key events
The example I posted will reveal top row function key codes too, at least on macOS. If it does not, try holding down the “fn” key when you press a top row function key and see if a code appears in the MessageBox.
System Preferences at one time had a setting where the “fn” key was required to be held down when a top row function key was pressed to have it act as a “regular function key”.
KeyCode2.zip (5.7 KB)
thank you again!
now i understood how to think in the right way to get the asyncKeys!
I don’t agree about that.
That key doesn’t produce an event nor is it detectable by Keyboard.AsyncKeyDown. I don’t know of a way to know when it’s held down.
Yes; you can make a utility for that (or have one already existing), but even with installing no app, it takes less than 10 seconds (assuming Xojo is already running) to create a new Xojo project, add the keydown event to the main window and write this:
for i as Integer=0 to 127
if Keyboard.AsyncKeyDown(i) then MessageBox i.ToString
Next
Just to check the value (except for dead keys where you’d put this code in a timer, because they produce no keydown event).
How would you use them outside of a KeyDown event? And what values would you expect them to hold? The values from the last KeyDown processed? That could be quite removed from the current processing.
How would you use them outside of a KeyDown event?
A long time ago, I saw codes for making games where a timer (or thread) would monitor the pressed keys (for example, when the focus isn’t on the relevant control). That would fit in this use outside of a KeyDown event.
And what values would you expect them to hold? The values from the last KeyDown processed?
No, just the values held in the original event provided by the OS. Xojo doesn’t seem to pass all fields of the underlying event, like mouse x, mouse y and pressed keys, but classes like EventMonitorMBS do.
But my examples are from 20 years ago; this has possibly changed, albeit I wouldn’t expect such core functions to change so much.