Java Robot class keyPress not typing into google chrome - java

I'm trying to beat the game 'fastTyper 2' (basically just a typing game where you type words that appear as fast as possible) by using the java robot class to type in the letters for me. I've successfully taken in the letters to be typed. However, it seems that the robot's keyPress method isn't working due to some kind of protection the game has. Does anyone know of a way to get around this?
Thanks

I don't think that the game protection is stopping you because there is no way for a game(or any other program) to decide whether the key is pressed manually or programatically.
Maybe you need to check the logic at what point of time you need your Robot class to press the key and which key to press(and make sure that you pass correct parameter value to keyPress method)

Related

Pressing key at any point to make an action

I'm programming on java, so I have to make a game-like program. The game should be able to "pause" at any point. Can you press a key at any point so a message is displayed saying "game is paused"? Then when you press that key again it will say "game resumed"?
Thanks
It looks like you need to be able to read input directly from the keyboard into your game? Is your game built into a GUI or in the console?
This can be done by using the KeyListener interface Java provides.
https://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyListener.html
I'll assume your using swing so this tutorial should be pretty useful.
http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html
Sorry I can't go into more detail, more information about what you are trying to do in the comments would help me help you.
Edit: You mentioned you're using the command line. To get user input you can use java.util.Scanner
http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
Make a boolean, isPaused. If space is pressed, switch isPaused from true to false or vice versa. If isPaused is true, run the game, if not, run a pause screen instead.

Multiple keypresses only registering sometimes

I have an odd little bug that I can't seem to weed out. I have tried using the debugger in Eclipse, but I still can't seem to figure it out.
Basically, this is a very very basic engine for a platformer. A lot of the code is from a tutorial, but I have been slowly modifying it and making sure it is all working one little step at a time.
Right now, the problem is that when you are holding down right arrow + W + F you jump(W) to the right (Right arrow) and shoot a fireball (F). This works, however if you repeat the process on the left, you do not shoot the fireball.
I have done quite a bit of tracing, tracing when you enter the fireball loop, when you press the button, and a lot of other things. At the moment, it appears that the keypress for the F is not being registered. Of course, this may just be it isn't being updated or something else, I am not sure. I just know that the trace is not called for the key press event.
This seems to be only when the player is doing all three key presses. So normally you can shoot a fireball to the left, that works. I have uploaded the code to codesend, as it is pretty long and I didn't want to bog down Stackoverflow.
I am happy to provide any other of the code documents, I do think these four should be enough but if you think you need more I will be happy to provide it.
Thank you very much for your time.
CODE:
Abstract Class MapObject - Player extends this
Player
RPG Movement - Player movement engine
Level1State - handles the key presses
Please have a look at here. This is what I meant you to do. Kindly see this and let me know if this helped you or if you still have problems.
handle multiple key presses ignoring repeated key

Keyboard/Mouse Robot not working when focused on a certain application

So I am trying to use a robot (either keypress or mouse) to simulate some tests on an application. However, this program isn't allowing me to do so and I'm pretty sure it is a security feature. The application I am using is TEMS Investigation and I am trying to simulate a record and stop recording for some automated tests I have. The program I am using to automate these tests can not access TEMS so there is no way for me to do this without a Robot. So my questions are:
1) How can I override whatever it is that is preventing me from using my robot.
2) Would this be considered illegal if I did? I don't need to break any laws...I just want to get my testing done! lol
I can't even runs something as simple as:
Robot r = new Robot();
r.keyPress(KeyEvent.VK_F2);
r.keyRelease(KeyEvent.VK_F2);
It will run, as I have downloaded some software to tell me what keys I am pressing....just wont be recognized while the TEMS application has focus.
Update: I found out using Notepad I can't use any keys (like "ALT +
F") to perform any menu options. It doesn't even pull up the "File"
menu. I am able to simulate typing in text, just not the context menu.
What was really weird is that I can't even use mouseMove() while TEMS
has the focus
It sounds like your runtime has no knowledge of the TEMS app. If you start it in your java code it should work. For example the following:
Runtime.getRuntime().exec("notepad");
robot.keyPress(KeyEvent.VK_J);
Will bring up notepad and type in the letter J. Try exec-ing TEMS and then send the key press.
And no, it's not illegal.
UPDATE:
To open the file menu in notepad, you would do the following:
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F);
The two keys must be pressed together before a robot.keyRelease.

Converting Serial input to Keyboard Button-press

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.

Can I simulate game pad button presses with Java's Robot class (Java.awt.robot)?

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

Categories