Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How can I get the keyboard layout?  (Read 4056 times)
0 Members and 1 Guest are viewing this topic.
Offline gouessej
« Posted 2010-12-13 16:15:53 »

Hi!

I try to detect the keyboard layout (QWERTY, QWERTZ, AZERTY, DVORAK, etc...). I'm on Linux with an AZERTY keyboard and when I press the key "1" on the top of the keyboard (not the one on the numerical pad on the right side), the key code returned by KeyEvent.getKeyCode() is never VK_1, it returns VK_AMPERSAND. On a QWERTY keyboard, VK_AMPERSAND is on the same key than 7. I would like to use these keys as direct shortcuts to select a particular weapon like in Doom. JInput does not give a better result except if I press SHIFT and "1". I know getExtendedKeyCode might be useful but it is only in Java 1.7. I could use the InputContext but I'm not sure a Locale is enough to know which keyboard layout is used.

Do you know a way of getting the keyboard layout?

Offline pjt33
« Reply #1 - Posted 2010-12-13 17:12:18 »

Can't you use getKeyChar() for weapon selection?
Offline gouessej
« Reply #2 - Posted 2010-12-13 20:16:52 »

Can't you use getKeyChar() for weapon selection?
No I can't because the char returned for the virtual keys VK_NUMPAD1 and VK_1 is the same whereas the num pad is used to move and the numerical keys are used to choose a weapon. Knowing the keyboard layout would be useful to choose a nice equivalent to WSAD for each layout.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JL235

JGO Coder


Medals: 10



« Reply #3 - Posted 2010-12-13 20:57:03 »

If this is for personal use? If so then you could just have it ask you to press a stated key at startup (like 1). Have the layouts hard coded in and pick one based on the event it receives.

Alternatively you could build some scripts (bash, VBScript, etc) for getting the keyboard layout and then have your app just run that script. It's not elegant but it should work.

Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #4 - Posted 2010-12-13 21:19:15 »

Not that it wouldn't be a nice feature, but I don't think AAA FPS do anything special. Just allowing customization is enough.

Offline gouessej
« Reply #5 - Posted 2010-12-13 22:03:20 »

Ok it is possible to make a difference between the key that should use the code VK_1 and the key that uses the code VK_NUMPAD1 by using getKeyLocation() and the default Locale instance seems to contain almost the same thing than $LANG so it might be enough. My fix is there (not very elegant):
http://www.ardor3d.com/forums/viewtopic.php?f=10&t=999&p=7639#p7635

Offline gouessej
« Reply #6 - Posted 2010-12-20 23:50:19 »

Hi!

What returns KeyEvent.paramString() on Windows and Mac? On Linux, the scan code that should appear in this string is always zero and I don't know what is the raw code.

Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #7 - Posted 2010-12-28 10:26:36 »

Quote
Input methods are unavailable if (a) no input method written in the Java programming language has been installed and (b) the Java 2 implementation or the underlying platform does not support native input methods. In this case, input contexts can still be created and used; their behavior is specified with the individual methods below.
That is impressively on topic spam right there (his signature has links).

Offline ryanm

Senior Duke


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #8 - Posted 2010-12-28 11:01:36 »

That is impressively on topic spam right there (his signature has links).

Had. Wink
It's a copy and paste from InputContext javadocs.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (43 views)
2014-10-17 03:59:02

Norakomi (33 views)
2014-10-16 15:22:06

Norakomi (26 views)
2014-10-16 15:20:20

lcass (30 views)
2014-10-15 16:18:58

TehJavaDev (60 views)
2014-10-14 00:39:48

TehJavaDev (60 views)
2014-10-14 00:35:47

TehJavaDev (50 views)
2014-10-14 00:32:37

BurntPizza (66 views)
2014-10-11 23:24:42

BurntPizza (38 views)
2014-10-11 23:10:45

BurntPizza (80 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!