How to generate keystrokes for use by any program?

hotshot05

Skilled
I want to use use Processing(www.processing.org) to process digital input coming from an Arduino connected to the computer and generate keyboard presses which can be used as input by any program

e.g If I press a button on my Arduino, I want to make the computer see it as [Enter] key being pressed on a keyboard and the cursor moving to the next line. I want this keypress to be used by any program, not any particular program.

Note - Mine is a Arduino Duemilanove, not a UNO. So no chance of any USB HID implementation.

Note 2 - If someone knows of any other programming language/application via which I can implement something like this(generating keystrokes), please let me know.
 
Will the keypress sent by the C# program be interpreted in a full screen application running in the foreground?

e.g - A fullscreen powerpoint slideshow is running in the foreground. I generate Right arrow or Left Arrow keypress via the C# application. Will Powerpoint take the input?

Found that I can use Robot class in Java to implement the functionality that I desire. But it has a limitation in that keypresses generated may not be accepted by fullscreen applications running in the foreground.
 
#hotshot05 in java use robot class,

import java.awt.AWTException;

import java.awt.Robot;

import java.awt.event.KeyEvent;

public class RobotExp {

public static void main(String[] args) throws AWTException {

Robot robot = new Robot();

// Creates the delay of 5 sec so that you can open notepad before

// Robot start writting

robot.delay(5000);

robot.keyPress(KeyEvent.VK_H);

robot.keyPress(KeyEvent.VK_I);

robot.keyPress(KeyEvent.VK_SPACE);

robot.keyPress(KeyEvent.VK_
<
;

robot.keyPress(KeyEvent.VK_U);

robot.keyPress(KeyEvent.VK_D);

robot.keyPress(KeyEvent.VK_Y);

}

}

since processing is all java ,you could use the same class.after copying it over the library files.

final int CAPS_LOCK = 20;

final int NUM_LOCK = 144;

final int SCROLL_LOCK = 145;

Robot r;

void setup()

{

size(100,100);

try{

r = new Robot();

}catch(AWTException a){}

}

void draw()

{

int v = (int)random(3);

switch(v){

case 0:

r.keyPress(CAPS_LOCK);

r.keyRelease(CAPS_LOCK);

break;

case 1:

r.keyPress(NUM_LOCK);

r.keyRelease(NUM_LOCK);

break;

case 2:

r.keyPress(SCROLL_LOCK);

r.keyRelease(SCROLL_LOCK);

break;

}

}

PS: not my code , used once to control mediaplayer over arduino by ir remote
 
#hotshot05 in java use robot class,

import java.awt.AWTException;

import java.awt.Robot;

import java.awt.event.KeyEvent;

public class RobotExp {

public static void main(String[] args) throws AWTException {

Robot robot = new Robot();

// Creates the delay of 5 sec so that you can open notepad before

// Robot start writting

robot.delay(5000);

robot.keyPress(KeyEvent.VK_H);

robot.keyPress(KeyEvent.VK_I);

robot.keyPress(KeyEvent.VK_SPACE);

robot.keyPress(KeyEvent.VK_
<
;

robot.keyPress(KeyEvent.VK_U);

robot.keyPress(KeyEvent.VK_D);

robot.keyPress(KeyEvent.VK_Y);

}

}

since processing is all java ,you could use the same class.after copying it over the library files.

final int CAPS_LOCK = 20;

final int NUM_LOCK = 144;

final int SCROLL_LOCK = 145;

Robot r;

void setup()

{

size(100,100);

try{

r = new Robot();

}catch(AWTException a){}

}

void draw()

{

int v = (int)random(3);

switch(v){

case 0:

r.keyPress(CAPS_LOCK);

r.keyRelease(CAPS_LOCK);

break;

case 1:

r.keyPress(NUM_LOCK);

r.keyRelease(NUM_LOCK);

break;

case 2:

r.keyPress(SCROLL_LOCK);

r.keyRelease(SCROLL_LOCK);

break;

}

}

PS: not my code , used once to control mediaplayer over arduino by ir remote

#vidy Which media player?

When the media player is in full screen mode, did the key press generated by Processing/Java robot class work as expected?
 
as i sent virtual keys of media volume/play/pause/next previous ,able to access all media players even they no need to be in full screen mode,

and processing comes with robot class ,you just need to add "import java.awt.Robot;"

here are list of virtual keys to sent,

http://msdn.microsof...d375731(v=vs.85).aspx
 
as i sent virtual keys of media volume/play/pause/next previous ,able to access all media players even they no need to be in full screen mode,

and processing comes with robot class ,you just need to add "import java.awt.Robot;"

here are list of virtual keys to sent,

http://msdn.microsof...d375731(v=vs.85).aspx

Thanks for the key codes.

Controlling the media player is not my only objective. As I have mentioned, I may also be trying to change slides in full screen slideshows of presentations. Will try t implement this and see if it works or not.
 
Back
Top