[GREENFOOT-135] Several keys are not recognised with Greenfoot.isKeyDown()
Greenfoot.isKeyDown seems to have problems recognising anything but the most basic keys.
Some examples of keys that can not be detected (on a British MacBook Pro keyboard): ' (Mapped to QUOTE, which can not be matched by isKeyDown("'")) And switching to a danish keyboard layout: ? (Mapped to SEMICOLON) ? (Mapped to QUOTE) ? (Mapped to OPEN BRACKET)
And many more. Have not tested on other platforms yet, but I suspect the problems will be similar.
This is because the keys are not necessarily reporting what is actually printed on the keyboard, but instead a keyCode which sometimes map to the correct character, but often it does not. It only works when the unicode of the character happens to map with the keyCode. I doubt this can be fixed in a robust way. There doesn't seem to be any way of detecting the actual layout of the keys from Java.
Maybe we need to abandon the concept of a key and use characters instead (and only use the key, if it doesn't have a character associated). This will make it difficult to detect when multiple keys are down at the same time, if one of the keys is a modifier key. For instance, pressing ALT-O on a british keyboard will produce a keyDownEvent with keyCode ALT and no character, then another keyDownEvent with keyCode 'O' and character '?'. If we only look at the character, we will then see the two keys ALT and 'O', as ALT and '?' which is not correct. We could be clever and detect that a modifier key is pressed at the same time when we get the '?', and then use the character derived from the keyCode (this will, however, be as broken as it is now).
Davin, do you have anything to add to this?
- Issue type: Bug
- Priority: Medium
- Fix versions: 3.0.0