Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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 4717 times)
0 Members and 1 Guest are viewing this topic.
Offline gouessej
« Posted 2010-12-13 16:15:53 »


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

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

« 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 Bitwise Duke »

Medals: 165
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):

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


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 Bitwise Duke »

Medals: 165
Projects: 4
Exp: 14 years

Esoteric Software

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

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 Devvie

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.

Riven (26 views)
2015-07-27 16:38:00

Riven (16 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (27 views)
2015-07-25 00:14:37

BurntPizza (39 views)
2015-07-24 22:06:39

BurntPizza (22 views)
2015-07-24 06:06:53

NoxInc (25 views)
2015-07-22 22:16:53

NoxInc (17 views)
2015-07-22 22:13:39

Jesse (39 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!