views:

157

answers:

2

Hi,

I'd like to be able to send key presses from one computer to the other. I have a voice application on one system which I use for my headset, and the other system is my main system. The voice application uses a Push-to-talk (PTT) system, which I'd rather keep.

So what I'd like to do is press a key on my main system and have it sent across the network to my secondary system. At this stage all I know is how to get the key across the network, the specifics of actually detecting the key press on my main system and emulating the press on the secondary system is my problem.

The key I'd like to capture (when held down) and send to my secondary system is the right control key. I think the best way is to add a keyboard hook.

How can I do this in such a way that I can hit right control in any application on my main system and have this application pick that up and send it? When my secondary system receives the key, how do I send it to the entire system (rather than trying to find a specific application)? I'm fine with using low-level Win32 calls in unmanaged C++, I'd just like to know how to get this to work.

Thanks in advance.

+1  A: 

It seems like you're already halfway there to your own custom solution, but as an alternate you might want to check out Synergy an open source keyboard and mouse extender.

Mike Buckbee
I'm currently using Synergy, but as far as I know it doesn't provide a method to send keypresses on one system to screens which don't have "focus" (ie, the other systems), which is what I'm looking for. I could modify it, I guess. +1 regardless.
Matthew Iselin
Yeah, you're right, some subtleties here I didn't consider. On your main system you might be able to macro in something to switch to Synergy when you hold the right ctrl key, passing the keypress to your main system and then back?
Mike Buckbee
Sounds quite complicated... I think I'm onto something after a bit of looking around on Google, that relates to keyboard hooks and the SendInput function (http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx). Thanks anyway!
Matthew Iselin
A: 

I found the answer: I wrote a small keyboard hook to pick up the PTT press, and then send it via the network to the secondary system. The secondary system takes this keypress and uses the SendInput function to inject the key into the system input queue. I just tested it with Teamspeak and it works brilliantly.

Matthew Iselin
For anyone interested, the actual source code (plus code for Linux too) is now here: http://code.google.com/p/netkeys.
Matthew Iselin