LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make game controller simulate keyboard stroke within an emulator?

So my goal is to use a game controller to simulate keyboard strokes in real time on the compuer. For example, I want to create a VI where the d-pad emulates the W, S, D, and A keyboard strokes which is usually associated as up, down, left and right in most flash games or emulators. Likewise, I want the A, X, Y and B buttons on the controller to simulate the down, left, up, and right strokes on the keyboard arrows. My goal is to be able to use a game controller on any flash game, or emulator where controllers aren't supported and only a keyboard can be used. I have already created a VI which can read the signals from the game controller but I don't know how to send those signals as keyboard strokes so that the computer reads them as if it came from the keyboard. 

 

Thanks,

Nick

0 Kudos
Message 1 of 8
(5,279 Views)

If you want to use a keyboard as a Game input device in LabVIEW, one way to do this is to set up an Event structure to fire whenever a key is presed, and to pass the keystrokes to a Consumer loop to detect which key was pressed and to take appropriate action.

 

If you are using a Game Controller, you should be able to something similar.  I'm not sure if there is a built-in Event code for Controllers, but one could always "fake" it by reading it periodically and parsing the results.  The only "catch" is that this involves reading the USB bus, and this might make things a little slow (I haven't tried seeing if you can "loop" a Controller without soaking up all of the CPU cycles).  If you can run such a loop without bogging down the system, you can similarly call an appropriate Consumer loop.

 

Bob Schor

0 Kudos
Message 2 of 8
(5,258 Views)

So I was able to make a straight forward vi using queues. I tried to use event structures but I was unable to make the vi see a value change on the booleans. I tried using property value signaling but was unable to get it to work. My vi is pretty basic and straight forward. Unfortunately there are a lot of sequence structures and I don't know how to make it more organized or more compact. It works really well for the most part. I have tested it on flash games online and even a few different emulator games. All you have to do is figure out what keys the keyboard uses and then assign them to the controller interface. If anyone has any advice on how I can simplify this or make it more compact I am all ears. Thanks.

0 Kudos
Message 4 of 8
(5,214 Views)

Oh and on a side note it doesn't use too much cpu but it uses a fair amount of ram. 

0 Kudos
Message 5 of 8
(5,213 Views)

Why are you creating queues in each of those sequence structures, enqueuing, immediately dequeuing, then killing the queues on every loop iteration.  There is no point to doing any of that.

 

By the way, use index array to get the value of a particular element of an array.  The Array to Cluster, then Unbundle is a Rube Goldberg.

0 Kudos
Message 6 of 8
(5,204 Views)

For some reason, when I had it set up prior it was spitting out like 30 keystrokes everytime I quickly pushed the button. I was observing the output through notepad. If I quickly pushed the button half a dozen times, it would load the crap out of wordpad and almost freeze up the program. In a flash game it would result in the character jumping continuously from 1 single button push for example. I attempted to use the first value only from the queue for every true false statement so that every loop iteration it would only output one value for every boolean change. It seemed to fix the issue. or maybe it was something else I did. 

0 Kudos
Message 7 of 8
(5,183 Views)

You have 100 msec waits in there (by the way, you only need one in the loop and not one per sequence structure, but that would go away when you eventually eliminate all the duplicate code) so it would only jump 10 times per second if you help down the button long enough.  If you only want one per button press, then use logic so it executes only on the false to true boolean change.  See F->T rising edge detection for examples.

0 Kudos
Message 8 of 8
(5,165 Views)