As far as I can see, unless I make my own method to return this information, I have to go and manually find the keycode for keys within the documentation. Is there a method which I can use instead of the table in the Xojo docs?
That would work something like this:
Function KeyCode(key as string) As integer
select case key
case "Left"
return &h7B
case "Right"
return &h7C
end select
End Function
So instead of finding it in the docs and using: ‘&h7B’ I could use ‘KeyCode(“Left”)’.
[quote=174460:@Oliver Scott-Brown]As far as I can see, unless I make my own method to return this information, I have to go and manually find the keycode for keys within the documentation. Is there a method which I can use instead of the table in the Xojo docs?
That would work something like this:
Function KeyCode(key as string) As integer
select case key
case "Left"
return &h7B
case "Right"
return &h7C
end select
End Function
So instead of finding it in the docs and using: ‘&h7B’ I could use ‘KeyCode(“Left”)’.
Thanks[/quote]
Keep in mind that keycodes refer to the physical keys, and because different languages have different layouts, they could refer to different keys on non US-English keyboards.
[quote=174470:@Oliver Scott-Brown]Thanks for the suggestions. These make sense. How would I avoid this conflict between different keyboards or is this not common?
Thanks[/quote]
You don’t use keycodes. Keyboard differences are very common for different languages.
FWIW, if all you are trying to do is get the arrow and function keys, you’ll probably be okay. It’s the letters that are usually different, but I’d at least ask some of our non-us users to try out your code.
[quote=174472:@Greg O’Lone]You don’t use keycodes. Keyboard differences are very common for different languages.
FWIW, if all you are trying to do is get the arrow and function keys, you’ll probably be okay. It’s the letters that are usually different, but I’d at least ask some of our non-us users to try out your code.[/quote]
Ok thanks.
Is this dependant on the actual physical keyboard attached, or the country settings of the OS???
For example:
The letter e on my UK keyboard is 101
If I was using for example, a german keyboard, but with my OS language still set to UK - are you saying the keycode would change??
I am trying to find out if it is the actual keyboard, or the OS country setting which would cause a change in the actual keycode.
Is this dependant on the actual physical keyboard attached, or the country settings of the OS???
For example:
The letter e on my UK keyboard is 101
If I was using for example, a german keyboard, but with my OS language still set to UK - are you saying the keycode would change??
I am trying to find out if it is the actual keyboard, or the OS country setting which would cause a change in the actual keycode.
[/quote]
Keycodes are the actual physical place where the key is, so they do not change if you have a different language setting.
Ok - German and UK keyboards swap the letters y and z
So basically the keycode for the letter y on my UK keyboard, would be different if I was using a German keyboard, as that would actually be a z?
[quote=174505:@Richard Summers]Ok - German and UK keyboards swap the letters y and z
So basically the keycode for the letter y on my UK keyboard, would be different if I was using a German keyboard, as that would actually be a z?
Have I understood this correctly?[/quote]
Nope. Sorry. Let me try again.
Keycodes in the Keyboard class report the key itself. NOT what it generates. So when you test for key &h10, you simply know the 6th key from the left on the typewriter upper row has been pressed. You may think about it as an electrical switch. Then the keyboard driver will decide what to do with that switch. Do Y/y for a French or English keyboard, Z/z for a German keyboard; Hiragana “N” ? for a Japanese keyboard, and so on.
The keycode remains the same, the key in keydown differs.
[quote=174505:@Richard Summers]Ok - German and UK keyboards swap the letters y and z
So basically the keycode for the letter y on my UK keyboard, would be different if I was using a German keyboard, as that would actually be a z?
Have I understood this correctly?[/quote]
Yes, I believe you have.
I just checked what happens. I was wrong. The keycode indeed changes with the driver. Sorry.
Incidentally, this means that the question the OP asked is answered by that : to a keycode corresponds a key. A dictionary can easily carry out the translation.
[quote=174569:@Michel Bujardet]I just checked what happens. I was wrong. The keycode indeed changes with the driver. Sorry.
Incidentally, this means that the question the OP asked is answered by that : to a keycode corresponds a key. A dictionary can easily carry out the translation.[/quote]
Did you check with a keyboard sold to be for another language? and what platforms did you test on?
How does one consistently check for a certain key being pressed, if keycodes are only relative to the developer’s keyboard layout, and not necessarily to end user’s?