Moose512
Posts: 4
Joined: Fri Jul 17, 2015 6:44 am

Sending script output from Pi to Windows

Fri Jul 17, 2015 6:50 am

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.

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Sending script output from Pi to Windows

Fri Jul 17, 2015 9:24 am

You can't do it with a RPi. Look at getting an Arduino set-up as a slave keyboard HID device.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Sending script output from Pi to Windows

Fri Jul 17, 2015 9:53 am

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.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
RST8
Posts: 64
Joined: Tue Nov 25, 2014 1:57 pm

Re: Sending script output from Pi to Windows

Fri Jul 17, 2015 10:16 am

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

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Sending script output from Pi to Windows

Fri Jul 17, 2015 10:50 am

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
Douglas6
Posts: 4860
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Sending script output from Pi to Windows

Fri Jul 17, 2015 3:31 pm

Or, use Bluetooth HID.

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Sending script output from Pi to Windows

Fri Jul 17, 2015 4:22 pm

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).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Moose512
Posts: 4
Joined: Fri Jul 17, 2015 6:44 am

Re: Sending script output from Pi to Windows

Fri Jul 17, 2015 6:38 pm

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!

Return to “Beginners”