05-02-2015 06:41 PM
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
05-02-2015 09:48 PM
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
05-03-2015 05:48 AM
05-03-2015 03:14 PM
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.
05-03-2015 03:15 PM
Oh and on a side note it doesn't use too much cpu but it uses a fair amount of ram.
05-03-2015 03:36 PM
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.
05-03-2015 04:45 PM
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.
05-03-2015 07:44 PM
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.