Do something (run script) on keystroke, NOT button press

Using an Arduino Uno and Leonardo.

I'm trying to get the Arduino to listen to keystrokes from my computer to initiate a script, rather than a button push--it's seems that everything else I've seen is done with a button put into a circuit, which is what I'm trying to avoid. The next closest thing I've found is Keyboard.write available on the Leonardo . . .

This is close, but I'd like to listen to keystrokes without using the serial monitor. Is this possible? Or, if I can't eliminate using the serial monitor, is there a way I can initiate it at the start of a script and then hide it, so that it does it's purpose of reading keystrokes but doesn't pop up on my screen?

Any and all help is greatly appreciated. Let me know if you need more info--I'm a first time poster.

I'm trying to get the Arduino to listen to keystrokes from my computer

What program on the PC is sending data to the Arduino? The Arduino can not get any data directly from the keyboard. It can not get any data directly from any device attached to the PC.

The Serial Monitor application is only one application that can run, monitor keystrokes, and send them to the serial port. Write your own that doesn't present a window.

The Serial Monitor application is only one application that can run, monitor keystrokes, and send them to the serial port. Write your own that doesn't present a window.

To be honest, I don't like your answer, but I have to think it's the right answer, as I can't think if any other way to send keystrokes to the serial port. Thanks for your input. Now I'm going to brush up on my java to see if I can write my own version of a serial monitor . . .

You haven't explained what you're trying to achieve and you don't say what OS you're running on the PC, but if you're running in a windowing environment then taking keyboard focus without collaborating with the window manager would be extremely unfriendly. Unless your application is going to run fullscreen, I would have thought that you would want to use an input window and follow the usual practice for accepting focus handling keyboard input events.

Running Windows 7 on PC.

I have an aduino (can be Uno or Leonardo), pushbutton, and Bluesmirf all in circuit. Ideally, when the pushbutton is pushed, I'd like the arduino to start some version of a serial monitor where it's running silently and the window is not present, and each keystroke would correlate to some command sent over bluetooth. Press the pushbutton again and serial communication would turn off.

I realize not having a window would be unfriendly, but the user would know exactly what keystroke correlates to what command. Ideally, I'm also trying to see if this is something that can be packaged entirely on the arduino. I'd rather avoid installing some seperate software on the PC to work with some script on the Arduino to accomplish this task.

If I understood you right, you want to be able to push a button attached to the Arduino and have it become activated. When activated it grabs keyboard focus and looks for specific keys (or key sequences?) that constitute BT commands. When it recognises a command it sends some predefined message over the BT connection. Push the button again and the Arduino will deactivate. Is that the idea?

There seem to be some conflicting requirements. If you want the solution to work without installing any software then the Arduino will need to emulate a device that is supported natively by Windows. I can't think of any natively supported devices that would enable you to grab keyboard focus - the closet I can see would be a mass storage device configured to autorun an application that did the monitoring for you - and I don't know whether it's possible for the Arduino to emulate a mass storage device.

If you relax the requirements and allow some software to be installed, you may be able to set up some hotkeys corresponding to the commands you want to run and configure the hotkey commands so that they cause a message to be written to the Arduino's serial port which commands the Arduno to send a predefined message over the BT port. Some of the details of how you'd do that that are a bit unclear and in particular how you would avoid opening and closing the serial port for each command. You might need to implement a proxy on the PC that can receive commands from the hotkey functions and manage opening the serial port and sending commands to it as required. For example, you could create a small C# application with a COM interface, and a COM client launched by a hotkey which sent messages to the Arduino via that interface.

If I understood you right, you want to be able to push a button attached to the Arduino and have it become activated. When activated it grabs keyboard focus and looks for specific keys (or key sequences?) that constitute BT commands. When it recognises a command it sends some predefined message over the BT connection. Push the button again and the Arduino will deactivate. Is that the idea?

That's pretty much it.

I suppose I can relax the requirements a bit and have some software installed on the PC. I think the biggest hurdle at this point is activating and deactivating serial communication on a button push, and making it run behind the scenes.

Has anyone used Gobetwino to accomplish something similar to this? I haven't read up on it yet, but it sounds like it may offer something close to what I'm looking for.

cobujo:
Using an Arduino Uno and Leonardo.

I'm trying to get the Arduino to listen to keystrokes from my computer to initiate a script, ...

How about this, or something like it?

Plug your keyboard in, intercept keystrokes, and act upon them. Pass them on to the computer so you can still use the keyboard.

Thanks Nick, I've taken a good look at that key counter and will continue to look. I'm wondering, since I'd like my device to be able to work from a laptop (and the keyboard counter is intended to go between the keyboard and computer), would I be able to split out a miniDIN6 cable on the computer end of the keyboard counter, and wire those cables accordingly to my arduino or bluesmirf to accomplish my objective?

Along with that, what would I have to do to get my laptop keyboard to act as the 'keyboard' on this device? If I hooked the keyboard end up to my laptop, would it output pure PS2 commands just as a keyboard would?

Also, would a usb to ps2 adapter inhibit this device?

Sorry for the flood of questions--I don't expect you to be able to answer all this, but any and all help is appreciated.