Page 1 of 1

Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 6:50 am
by Moose512
I know the title doesn't do a great job, but here's the situation:

I have a physical push button connected to my Raspberry Pi's GPIO pin 18.
I wrote a script that, when receiving button input, outputs the keystroke W.
Script runs great on Raspberry Pi, no problems there.

Now, here's the rub:

The goal is to have a switch that, when pressed, activates a button in a computer game on my windows machine. My motherboard doesn't have an RS-232 port and I don't understand how USB works enough, so I'm using the Pi as the button interface. I want to take that W keystroke from the Pi and make my Windows computer execute that command.

Anyone able to point me in the right direction? I may post pictures and diagrams tomorrow. Too tired tonight,

P.S. Both computers are network connected and I SSH through PuTTY.

Re: Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 9:24 am
by DougieLawson
You can't do it with a RPi. Look at getting an Arduino set-up as a slave keyboard HID device.

Re: Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 9:53 am
by Joe Schmoe
ISTM that the key (no pun intended) issue here is: How time critical is it (the Windows app) ? If the answer is "not very", then there are easy solutions. If, however, as I suspect, it is time critical, then it will be harder.

I'm also curious about your references to RS232 and USB. If you could say a little more about how those things might help or be relevant, it would be helpful.

Re: Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 10:16 am
by RST8
Moose512 wrote:I know the title doesn't do a great job, but here's the situation:

I have a physical push button connected to my Raspberry Pi's GPIO pin 18.
I wrote a script that, when receiving button input, outputs the keystroke W.
Script runs great on Raspberry Pi, no problems there.

Now, here's the rub:

The goal is to have a switch that, when pressed, activates a button in a computer game on my windows machine. My motherboard doesn't have an RS-232 port and I don't understand how USB works enough, so I'm using the Pi as the button interface. I want to take that W keystroke from the Pi and make my Windows computer execute that command.

Anyone able to point me in the right direction? I may post pictures and diagrams tomorrow. Too tired tonight,

P.S. Both computers are network connected and I SSH through PuTTY.
There are a number of approaches, possibly not all that trivial, but it seems to me you are going to need an executable running on the Windows machine that is listening for a response from the Pi and then uses something like SendKeys() to the Windows app.
At the most basic level, you could have the Pi write a file to a share on the Windows machine, that your listening app monitors for the creation of a file; crude, kludgy, bit it will probably work.
You could use a sockets based approach, potentially more reliable, but not as easy to code.

SendKeys
You would need to ensure that your game window has focus before calling sendkeys, which probably means using the old FindWindow call
http://stackoverflow.com/questions/2817 ... ons-window

Of course you don't have to use C# and this is not a particularly elegant approach, but needs must when the devil drives

Joe

Re: Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 10:50 am
by DougieLawson
Doing it with an Arduino is a lot less clunky.
http://mitchtech.net/arduino-usb-hid-keyboard/

The Arduino simply appears as a keyboard and Windows does it's normal stuff, no special programs needed on Windows.

Re: Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 3:31 pm
by Douglas6
Or, use Bluetooth HID.

Re: Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 4:22 pm
by DougieLawson
Douglas6 wrote:Or, use Bluetooth HID.
Does that work with the RPi as a the slave device and Windows as a HID master?

I thought the BT HID support worked the other way round so you can use a slave BT keyboard on a RPi (as master).

Re: Sending script output from Pi to Windows

Posted: Fri Jul 17, 2015 6:38 pm
by Moose512
I mentioned RS-232 because that is how I used to connect my ham radio to my PC. I'm pretty new to all this, and don't own an Arduino. I found a kludgy way of making it work, which is fine for me I love kludges. Using uinput in python to have a switch mimic a keystroke, then simply using VNC from the Pi to my PC, pressing the button and tada the program receives the information. Not sure what an HID is but I'm definitely going to research that. Thanks guys, you have helped a bunch!