I'm writing a game based on terminal and I want capture keyboard event, such as w/a/s/d as direction of Up/Left/Below/Right, rather then readLine a input stream with a Enter key.
Besides, I have read swing package, it has some KeyListener interface but it seems must bind with swing UI.
Does there have pure keyboard event without other technology binding in java world?
Related
On Mac, the US International PC keyboard layout has dead keys for several keys such as ", ' and backtick. When typing ", the Mac starts input method composition - the " shown in compose mode (usually underlined) and waits for further input. If I use a, then the input method will complete and I'll get the character ä. There are several such dead keys, and e.g. the British keyboard layout treats Alt+n as a dead key to give something like ñ.
In a Java AWT application, is there any way I can disable this behaviour so that I get simply the raw keys typed? E.g. in the US International PC keyboard layout, if I type "+a, I want to receive events for " and a, and not one event for ä. In the British keyboard layout, I want to type Alt+n+n and receive events for Alt+n and n and not ñ.
If I call Component.enableInputMethods(false), then my event queue will receive the Alt+n event, but if I then follow with n, I receive ñ.
Similarly, if I use a Chinese keyboard layout, the popup input method is still active, even after calling Component.enableInputMethods(false).
Is there any way to completely disable input method processing, and receive just the keys, as typed?
For context, I'm trying to implement Vim like behaviour - normal mode editing requires ASCII input, while insert mode will of course handle input methods as expected. While it would be ideal to swap to an ASCII keyboard layout in normal mode, but even the Mac's "ABC" keyboard layout has dead keys for Alt+n, Alt+u, Alt+I and Alt+e and Alt+Backtick. Telling users to create a custom keyboard layout with something like Ukulele is not a viable option.
I made a simple JFrame with Swing. I want to know how I would go about making a non-visible input that would open up another JFrame I have in another class. (Like cheat codes in video games, you enter a combination and something happens.) I am not sure how to capture the user input without a text field.
You should use keybinding attached to your JFrame. You would want to store keystrokes as a String internally and after each keystroke, see whether the user has entered a recognizable cheat code or just listen for a return keypress as a delimiter for the code.
Keep in mind that if a component within that JFrame has focus and also implements the same key bindings, then that component will take precedence over the JFrame, effectively intercepting the keystrokes.
Not sure if I'm asking this question on the correct site (I have been wondering if this should rather be posted on the EE.stackoverflow site).
So I have an OLD serial input mouse, and I want the system to reprogram or retranslate it to a keyboard button-press.
The whole thing is that I have software with shortcut keys, but remembering all of them is just not possible. So, why does one want to have a whole keyboard when one can only have a set of three buttons? Using a keyboard, when one presses F11 (and holds it in), it activates the system's mic. While holding in F11, one wants to press F1 to start playing music, thus being a voice over song application.
I've been trying to research the possibility, and I've come to notice that there are a LOT of applications that can convert a USB device, such as a game controller to a keyboard button-press. That's what's driving my concept.
Is this even possible?
Thanks,
Johan Brink
Well, as described here, if you are using Windows, you can use X-Mouse Button Control for mouse. If you want to use gamepad, try J2K - A Joystick to Keyboard Mapper 1.1
Have a look on Makey Makey (www.makeymakey.com). This is a board which emulates a key stroke each time one of his input is closed.
I'm using an Arduino Uno to hook a (genuine) SNES controller to a computer via USB or Bluetooth.
The Arduino captures the controller's button presses and releases using the snespad library. It communicates button presses and releases as characters (e.g. 'a' for pressing A, 'A' for releasing 'A'). Next, a Java program listens to the serial output using the rxtx library. Finally, a Java robot simulates key presses using the keyPress and keyRelease.
Unfortunately, this approach has a few drawbacks. The main issue is key mapping. I kind of arbitrarily decided which buttons would be which keyboard keys.
Java doesn't appear to have any game pad KeyEvents. When I say "game pad KeyEvent," I mean something like what the Android SDK has: http://developer.android.com/reference/android/view/KeyEvent.html (ctrl+f "game pad" or "button".)
My question is, is there a way to simulate game pad button presses instead of keystrokes using Java's robot class?
USING THE ROBOT CLASS IN JAVA
You can create virtual keypresses/releases in the following way...
Robot robo=new Robot();
robo.keyPress(KeyEvent.VK_A);
//don't forget to release it else you'll land up in infinite loop
robo.KeyRelease(KeyEvent.VK_A);
cheers
You should be able to easily from my expierience the gamepad buttons are mapped to keyboard buttons the only mapping i know it i,j,k,l go to looking around and w,a,s,d go to moving around
I have a calculator application in java swing, which is working properly with mouse click input. Now I want it to read input using keyboard button stroke. I had heard about the glass pane in java tutorial, but i need to know any other simple method to meet the requirement.
KeyPadPanel is an example that uses Action and Key Bindings for numeric entry.