Hello everyone!
How are you doing?
I want to get the key codes from my keyboard, for each key i press.
( i want to use it on a “select case Keyboard.AsyncKeyDown()” )
How can i do that?
Thank you!
Alex
Hello everyone!
How are you doing?
I want to get the key codes from my keyboard, for each key i press.
( i want to use it on a “select case Keyboard.AsyncKeyDown()” )
How can i do that?
Thank you!
Alex
If you just want to know what it returns for a given key assign it to a variable and run it in the debugger. Run it and press the key, check the variable afterwards?
On macOS there’s an app for that.
i want to change this:
If Keyboard.AsyncKeyDown(getKeyCode("Arrow Up")) Then // Up Arrow
c_game.myMouse.Move("UP", c_game)
ElseIf Keyboard.AsyncKeyDown(getKeyCode("Arrow Right")) Then // Right Arrow
c_game.myMouse.Move("RIGHT", c_game)
ElseIf Keyboard.AsyncKeyDown(getKeyCode("Arrow Down")) Then // Down Arrow
c_game.myMouse.Move("DOWN", c_game)
ElseIf Keyboard.AsyncKeyDown(getKeyCode("Arrow Left")) Then // Left Arrow
c_game.myMouse.Move("LEFT", c_game)
End If
to this
Select case Keyboard.AsyncKeyDown(getKeyCode)
case 1
case 2
case 3
End select
cool!!!
but i want to get the keycodes using Xojo…
So you want to take the very long If…Else If…Else and change it to a Select Case?
Xojo Select Case
getKeyCode isn’t a stock Xojo function. If you just write a simple program that displays or stores Keyboard.AsyncKeyDown then you can inspect it and find the code. Once you have each code you can fill in your case 1, 2 etc.
In a KeyDown event handler.
Function KeyDown(key As String) Handles KeyDown as Boolean
Select Case key
Case Chr(28) ' L
Case Chr(29) 'R
Case Chr(30) 'U
Case Chr(31) 'D
End Select
no. it was only an example.
i just want to capture the keycodes.
is there a way to get the key code of a key, when it’s pressed on xojo?
if not… why not?!
ok. let’s go deep onto it. another example:
suppose i did a xojo app for mac. us-english keyboard. everything is fine!
now, i want to do another app, using french keyboard…
and imagine you, that i can’t find the key codes for that keyboard anywhere…
BUT: i have the keyboard with me. at my own hands!
that’s it… i want to get the keycode when i press the key on keyboard.
Fair point.
According to the internet:
Yes, arrow key keycodes are always the same, regardless of the keyboard layout.
I regularly use different keyboard layouts (Dvorak, Russian, Ukrainian, Hebrew, Spanish) and I have tried all of them in JavaScript and they give consistent results for the arrow keys.
37: ‘left’,
39: ‘right’,
38: ‘up’,
40: ‘down’
Many games give the user a way to define which keys they would like to use. You could start with reasonable defaults (arrow keys) and let them configure them via a “press the key you want to use” interface - that would let you capture the key code for whatever keyboard they may be using without having to know anything about it or the key they are pressing.
I asked the Language reference, typed Cmd-K then Key Code in the search window.
I am sure you will get there the info you need.
i don’t know what “keycodes” are those… but on macos, the arrow keycodes are:
up, right, down, left: 7E, 7C, 7D, 7B
and the ascii on mac are 30, 29, 31, 28…
there is a initeresting method that give a name to a keycode
MessageBox(Keyboard.keyname(&h7D))
and there is a list for US Keyboard.
for game input you could consider using mouse via screen input icons,
a game pad or touch screen input.
or user assign movement keys, maybe people like awsd.
yep!!
how do i catch the keycode?
that’s what i need: the keycode, not the asci code of the key was pressed, because i’ll use Keyboard.AsyncKeyDown(keyCode As Integer), not the KeyDown(key as string)
but i need to insert the string inside.
i need to catch the keycode
hum… thinking again… maybe it works…