Sign in to follow this  
Followers 0
Baritonomarchetto

Sending keyboard key press to emulators

2 posts in this topic

#1 ·  Posted (edited)

Hi All,

first of all, nice to meet you ;)

This is my first topic here and, i hope, the first of a long serie.

I found that AutoIt could be the right solution to an input problem some Racing emulators gives to users: the shifter handling.

Essentially, shifters used in arcades like SEGA's from the 90's are 4 position shifters and emulators handle them associating each position to a key on the keyboard. What i am trying to script is the sequential shifter support i.e. : if i press "down arrow" the first time, Autoit sends "Q" Keypress, the second time "W", the third time "E" and "R" the fourth time. Similarly, while pressing "up Arrow" i would obtain a gear lowering.

I wrote a little (and very dirt not being a programmer) Autoit script to associate to sequential keypress of the down arrow and up arrow to that serie of buttons but, even if working with notepad, it seems not to act correctly with emulators (i tried with MAME actually, even if my target is Model 2 Emulator): sometimes the emu sees the key press, sometines not, sometimes i have a non sequential jump between gears...

Here it is (i also attached it here):

#include <Misc.au3>

Local $hDLL = DllOpen("user32.dll")

Local $shifterpos = 1

;WinWaitActive("MAME")

While 1
If _IsPressed("28", $hDLL) Then ; 51 DOWN ARROW
If $shifterpos ==1 Then
         Send("w")
While _IsPressed("28", $hDLL)
         Sleep(150)
WEnd
$shifterpos = 2
    
ElseIf $shifterpos ==2 Then
         Send("e")
While _IsPressed("28", $hDLL)
         Sleep(150)
WEnd
         $shifterpos = 3

ElseIf $shifterpos ==3 Then
         Send("r")
While _IsPressed("28", $hDLL)
         Sleep(150)
WEnd
         $shifterpos = 4

EndIf
EndIf
If _IsPressed("26", $hDLL) Then ; 26 UP ARROW
If $shifterpos ==4 Then
         Send("e")
While _IsPressed("26", $hDLL)
         Sleep(150)
WEnd
         $shifterpos = 3

ElseIf $shifterpos ==3 Then
         Send("w")
While _IsPressed("26", $hDLL)
         Sleep(150)
WEnd
         $shifterpos = 2

ElseIf $shifterpos ==2 Then
         Send("q")
While _IsPressed("26", $hDLL)
         Sleep(150)
WEnd
         $shifterpos = 1

EndIf
EndIf
WEnd

DllClose($hDLL)

Any help? What is wrong here? Thanks alot

Edited by Baritonomarchetto

Share this post


Link to post
Share on other sites



This is my first topic here and, i hope, the first of a long serie.

Really? So you hope to be completely worthless who can't do anything on your own and requires the assistance of the community for even menial tasks? That's not exactly an auspicious greeting to a community that is all about teaching people to fish as it were.

Anyway, I suggest you read the forum rules. By suggest I mean go read the forum rules. Now. You are breaking them.

Thread locked.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0