Ejoc Posted April 28, 2005 Share Posted April 28, 2005 (edited) A joystick UDF, requires beta >= 3.1.1.18 expandcollapse popup#include <GUIConstants.au3> Local $joy,$coor,$h,$s,$msg $joy = _JoyInit() GUICreate("Joystick Test",300,300) $h= GuiCtrlCreatelabel("",10,10,290,290) GUISetState() while 1 $msg = GUIGetMSG() $coor = _GetJoy($joy,0) $s = "Joystick(0):" & @CRLF & _ "X: " & $coor[0] & @CRLF & _ "Y: " & $coor[1] & @CRLF & _ "Z: " & $coor[2] & @CRLF & _ "R: " & $coor[3] & @CRLF & _ "U: " & $coor[4] & @CRLF & _ "V: " & $coor[5] & @CRLF & _ "POV: " & $coor[6] & @CRLF & _ "Buttons: " & $coor[7] GUICtrlSetData($h,$s,1) sleep(10) if $msg = $GUI_EVENT_CLOSE Then Exitloop WEnd _JoyClose($joy) ;====================================== ; _JoyInit() ;====================================== Func _JoyInit() Local $joy Global $JOYINFOEX_struct = "dword[13]" $joy = DllStructCreate($JOYINFOEX_struct) if @error Then Return 0 DllStructSet($joy,1,DllStructSize($joy),1);dwSize = sizeof(struct) DllStructSet($joy,1,255,2) ;dwFlags = GetAll return $joy EndFunc ;====================================== ; _GetJoy($lpJoy,$iJoy) ; $lpJoy Return from _JoyInit() ; $iJoy Joystick # 0-15 ; Return Array containing X-Pos, Y-Pos, Z-Pos, R-Pos, U-Pos, V-Pos,POV ; Buttons down ; ; *POV This is a digital game pad, not analog joystick ; 65535 = Not pressed ; 0 = U ; 4500 = UR ; 9000 = R ; Goes around clockwise increasing 4500 for each position ;====================================== Func _GetJoy($lpJoy,$iJoy) Local $coor,$ret Dim $coor[8] DllCall("Winmm.dll","int","joyGetPosEx",_ "int",$iJoy,_ "ptr",DllStructPtr($lpJoy)) if Not @error Then $coor[0] = DllStructGet($lpJoy,1,3) $coor[1] = DllStructGet($lpJoy,1,4) $coor[2] = DllStructGet($lpJoy,1,5) $coor[3] = DllStructGet($lpJoy,1,6) $coor[4] = DllStructGet($lpJoy,1,7) $coor[5] = DllStructGet($lpJoy,1,8) $coor[6] = DllStructGet($lpJoy,1,11) $coor[7] = DllStructGet($lpJoy,1,9) EndIf return $coor EndFunc ;====================================== ; _JoyClose($lpJoy) ; Free the memory allocated for the joystick struct ;====================================== Func _JoyClose($lpJoy) DllStructFree($lpJoy) EndFunc_Joystick.au3 Edited April 29, 2005 by Ejoc Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs Link to comment Share on other sites More sharing options...
jpm Posted April 29, 2005 Share Posted April 29, 2005 you mean >=3.1.1.18 not over??? Link to comment Share on other sites More sharing options...
Ejoc Posted April 29, 2005 Author Share Posted April 29, 2005 you mean >=3.1.1.18 not over???<{POST_SNAPBACK}>correct Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs Link to comment Share on other sites More sharing options...
Adam1213 Posted March 31, 2007 Share Posted March 31, 2007 A joystick UDF, requires beta >= 3.1.1.18 (code was here) Nice program but it did not work with Autoit 3.2, I fixed this. When I made it work its blinking (info on GUI) was really bad (fixed) expandcollapse popup;____________________________________________________________________ ; Original program by Ejoc ; ; Improved by Adam1213 (autoit 3.2 compatiblity + improved labels ; ;____________________________________________________________________ #include <GUIConstants.au3> ;_________________ SETUP_____________________________________ Local $joy,$coor,$h,$s,$msg $joy = _JoyInit() dim $labels_text[8]=['X', 'Y', 'Z', 'R', 'U', 'V', 'POV', 'Buttons'] dim $labels_no=UBound($labels_text) dim $labels[$labels_no] dim $labels_value[$labels_no] ;__________ CONFIG ____________________________________________ ;---------- Find the max length of the longest label -------------- $label_len=0 for $text in $labels_text $len=stringlen($text) if $len>$label_len then $label_len=$len endif next $label_len*=6 ;_____________ GUI _______________________________________________ GUICreate('Joystick Test', 200, 200) GUICtrlCreateLabel('Joystick', 40, 20, 100, 20) for $i=0 to $labels_no-1 GuiCtrlCreatelabel($labels_text[$i]&':', 10, 60+$i*12, $label_len, 12) $labels[$i]=GuiCtrlCreatelabel('', 10+$label_len, 60+$i*12, 70, 12) $labels_value[$i]='' next GUISetState() ;_____________________________________________________________________ while 1 $coord=_GetJoy($joy,0) for $i=0 to UBound($coord)-1 if $coord[$i]<>$labels_value[$i] then GUICtrlSetData($labels[$i], $coord[$i]) $labels_value[$i]=$coord[$i] endif next sleep(10) $msg =GUIGetMSG() if $msg = $GUI_EVENT_CLOSE Then Exitloop WEnd $lpJoy=0 ; Joyclose ;====================================== ; _JoyInit() ;====================================== Func _JoyInit() Local $joy Global $JOYINFOEX_struct = "dword[13]" $joy=DllStructCreate($JOYINFOEX_struct) if @error Then Return 0 DllStructSetData($joy, 1, DllStructGetSize($joy), 1);dwSize = sizeof(struct) DllStructSetData($joy, 1, 255, 2) ;dwFlags = GetAll return $joy EndFunc ;====================================== ; _GetJoy($lpJoy,$iJoy) ; $lpJoy Return from _JoyInit() ; $iJoy Joystick # 0-15 ; Return Array containing X-Pos, Y-Pos, Z-Pos, R-Pos, U-Pos, V-Pos,POV ; Buttons down ; ; *POV This is a digital game pad, not analog joystick ; 65535 = Not pressed ; 0 = U ; 4500 = UR ; 9000 = R ; Goes around clockwise increasing 4500 for each position ;====================================== Func _GetJoy($lpJoy,$iJoy) Local $coor,$ret Dim $coor[8] DllCall("Winmm.dll","int","joyGetPosEx", _ "int",$iJoy, _ "ptr",DllStructGetPtr($lpJoy)) if Not @error Then $coor[0] = DllStructGetData($lpJoy,1,3) $coor[1] = DllStructGetData($lpJoy,1,4) $coor[2] = DllStructGetData($lpJoy,1,5) $coor[3] = DllStructGetData($lpJoy,1,6) $coor[4] = DllStructGetData($lpJoy,1,7) $coor[5] = DllStructGetData($lpJoy,1,8) $coor[6] = DllStructGetData($lpJoy,1,11) $coor[7] = DllStructGetData($lpJoy,1,9) EndIf return $coor EndFunc Huer 1 IRC Client - 75 pages 3728 lines. Blob crumbler (game)Backup (drag to backup + cmd line)RS232 Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 27, 2007 Share Posted June 27, 2007 (edited) What is this script supposed to do?? I just get a empty MsgBox.... EDIT: wait i just got it, i had to go to controlpanel>game devices and then choose my joystick to be the one used for older apps..... Edited June 27, 2007 by TzarAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
mattmiester4 Posted January 4, 2008 Share Posted January 4, 2008 very nice, just what i was looking for! - matt Link to comment Share on other sites More sharing options...
Alandor Posted January 4, 2008 Share Posted January 4, 2008 thaaaaaaaanx very much, something like that was what i was looking for starting an Joy2Midi script for use in music secuencer programs. Link to comment Share on other sites More sharing options...
eden Posted June 22, 2008 Share Posted June 22, 2008 (edited) Thank you both Ejoc and Adam, this is exactly what I need. I will be using it detect the movements of my n52te gamepad, and send additional keystrokes along with my movements in order to overcome some of the limitations in razor's programming software. Edited June 22, 2008 by eden Link to comment Share on other sites More sharing options...
RomanK Posted August 22, 2008 Share Posted August 22, 2008 Thank you so much! I was looking for this! [font="Courier New"]http://RomanK.hondadesigns.com[/font] Link to comment Share on other sites More sharing options...
Justin Posted October 15, 2008 Share Posted October 15, 2008 (edited) I can get this to read my joystick, and return button presses, but what would I need to script in order to translate joystick button presses into key presses? I am using a USB Rock band drumkit to control a game I've created in Flash, in an autoit container.. pretty awesome if this will work. EDIT: I figured it out -- it was a if $coord[7] = "1" Then Send("{RIGHT}") line. Perfect!! Can use this for the guitar hero guitar as well. Now, if there were any way of determining the name of each joystick plugged into the computer, that would be swell. Edited October 15, 2008 by Justin Link to comment Share on other sites More sharing options...
myspacee Posted April 13, 2009 Share Posted April 13, 2009 Reading about Joystick and AI interactions... Now i'm inoffice so i can't try, but udf is capable to detect also analog stick ? (and their diagonals?) Thank you for any info, m. Link to comment Share on other sites More sharing options...
orepmetiur Posted January 4, 2010 Share Posted January 4, 2010 Thank You so much Ejoc and Adam1213 for your posts! They were a great help pointing me the direction on the creation of an utility for the Logitech G25 H-Shifter.Now I can use the H-Shifter in old games!In case anyone be interested: My linko. Link to comment Share on other sites More sharing options...
jcval Posted March 15, 2010 Share Posted March 15, 2010 PortuguêsOlá pessoal,preciso saber como enviar o pressionamento de um botão no joystick, pois o jogo "street fighter 4" o player 2 não tem comandos no teclado.Alguém sabe me ajudar?Translate by googleInglêsHello everybody,need to know how to send the push of a button on the joystick, because the game "street fighter 4" player 2 has no controls on the keyboard.Someone help me know? Link to comment Share on other sites More sharing options...
Vicate Posted May 6, 2010 Share Posted May 6, 2010 Hi there, I am trying to create a program that works with my xbox 360 controller. Judging by the replies I am seeing on this thread with people with similar aspirations being helped by this UDF, I am assuming that this UDF is instrumental in the process. Unfortunately, though, I do not understand how this is an aid to me. The UDF is responding to activity on my controller, but I don't know how to apply these numerical values to my own work. If someone could provide some instruction as to how this UDF can help me to write a program that'll work with my controller, it would be greatly appreciated. Basically, I want to create a program that can: - Make arrow keys correspond to the left analog stick - Trigger Mouseclicks at certain xy coordinates by pressing buttons on the controller Thank you, -Chris Link to comment Share on other sites More sharing options...
Shafayat Posted May 6, 2010 Share Posted May 6, 2010 Get what button press returns what (by testing one by one). Then use the values and responding button to create a Switch.....Endswitch statement. Guess the rest. [Not using this account any more. Using "iShafayet" instead] Link to comment Share on other sites More sharing options...
orepmetiur Posted August 11, 2010 Share Posted August 11, 2010 Thank You so much Ejoc and Adam1213 for your posts! They were a great help pointing me the direction on the creation of an utility for the Logitech G25 H-Shifter.Now I can use the H-Shifter in old games!In case anyone be interested: My link *** Update: Released a new version in 2010-08-10o. Link to comment Share on other sites More sharing options...
orepmetiur Posted August 15, 2010 Share Posted August 15, 2010 Hi,I've release a freeware tool made with autoit v3 that allows a basic usage of the Nostromo N50 in Windows7, without the need of driver installation. You can have a look here.Thanks.o. Link to comment Share on other sites More sharing options...
magician13134 Posted September 26, 2010 Share Posted September 26, 2010 Sorry to bring up and old topic, but I'm trying to get this to work and I'm having some troubles. The script works great, but the numbers seem a little off. The number range I was getting was from 0-65535 (2^16) rather than 0-255 (2^8), so I just took the square root, but when the joystick is at rest, it reads ~180 rather than 128. This is true for all three axes. I have reset the joystick calibration in Windows, but I don't think that's the issue, because other programs read the joystick fine (as 128 when it's at rest). Does anyone know anything about this? Your help would be greatly appreciated. Thanks! Visit Magic Soft Inc. for some of my software Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted September 26, 2010 Share Posted September 26, 2010 @magician13134 Run the code from post #4. If it works, then whatever code you added is wrong. So either skip that weird conversion you are doing or post a reproducer (example) and I'm sure someone can help you. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
magician13134 Posted September 26, 2010 Share Posted September 26, 2010 @magician13134 Run the code from post #4. If it works, then whatever code you added is wrong. So either skip that weird conversion you are doing or post a reproducer (example) and I'm sure someone can help you. I did run the code exactly as posted in post #4, and that's what gave me weird results. I was just comparing those results to what another program was giving me simultaneously. I don't know if anyone else had this problem, but I compared a bunch of points that I was reading from the script in post #4 to what they should be and linearized it, so this is what I had to do to get it working... It may just be something wrong with my computer, but here's the equation I had to use$realPoint=10^(2.002*Log($coord[$i])/Log(10) - 2.413)That yields the proper coordinates for me... Visit Magic Soft Inc. for some of my software Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now