I have an application that is primarily keyboard driven. I was adding a new keyboard action to the application and came across something I wasn't aware of.
If I print out the
after pressing Ctrl-m the newline character (\n) is returned. Or since the application treats the char as an int, 10 is returned.
Interestingly, when pressing Ctrl-j,
returns the newline character as well.
Confused by this I opened notepad and pressed ctrl-m and then ctrl-j and noticed that they both add a newline to the file.
Does anyone have any tips on how I might differentiate between ctrl-m and ctrl-j in Java?
Edit: I've done some further research that I feel I should mention
The above issues of not being able to differentiate between ctrl-j and ctrl-m occurs if checking the KeyEvent in the KeyTyped method. One can differentiate if they check the KeyEvent in the KeyPressed method.
KeyTyped: java.awt.event.KeyEvent[KEY_TYPED,keyCode=0,keyText=Unknown keyCode: 0x0,keyChar=Enter,modifiers=Ctrl,extModifiers=Ctrl,keyLocation=KEY_LOCATION_UNKNOWN,rawCode=0,primar yLevelUnicode=0,scancode=0]
KeyPressed: java.awt.event.KeyEvent[KEY_PRESSED,keyCode=74,keyText=J,keyChar=Enter,modifiers=Ctrl,extModifiers=Ctrl,keyLocation=KEY_LOCA TION_STANDARD,rawCode=74,primaryLevelUnicode=106,scancode=36]
Checking in the KeyPressed method has been deemed not valid (By Authorities greater than me), so I'm still looking for a workaround when checking the KeyEvent in the KeyTyped method.