This site requires JavaScript, please enable it in your browser!
Greenfoot back
MrBradley
MrBradley wrote ...

2020/12/19

Greenfoot.getKey() with Shift

MrBradley MrBradley

2020/12/19

#
In GF 3.6.1 the getKey() method does not return any shift characters. Uppercase letters all appear as lowercase. Related, you cannot type and Shift-based characters like '?', '!', '@', '#', etc. getKey() returns "shift" when the shift key has been pressed and "control" for the control key. Is there a workaround or fix for this? act() { String input = Greenfoot.getKey(); if( input != null ) { System.out.println( input ); } }
Jackylein250 Jackylein250

2020/12/19

#
Have you tried checking if both "Shift" and in case of "!" "1" are pressed by combining them with an AND operator?
MrBradley MrBradley

2020/12/22

#
This was what I was hoping, but getKey() consumes the key and only scans a single key. It seems to me that getKey() should return a KeyInfo object, like MouseInfo, that also stores key combos like SHIFT+ and CONTROL+ and ALT+. At least it should remove SHIFT and CONTROL from consuming the intended key press. I could try using isKeyDown("") but .... Most importantly, the documentation states that getKey() recognizes Uppercase: "getKey() also returns uppercase characters when appropriate." But even with the CAPS LOCK on, getKey() does not return uppercase letters. I'm left wondering what conditions "when appropriate" are applicable!
You need to login to post a reply.