Damein Posted December 8, 2013 Posted December 8, 2013 (edited) I decided to use my PC controller as my mouse one day and realized I could create a decent little program for it. Now, since I only have the one controller I don't know how universal this will be (Although, I don't expect it to have many problems, save for Xbox controllers) but here it is. Here is a video demo as well YouTube Link expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Images\Controller.ico #AutoIt3Wrapper_Compression=0 #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=R.S.S. #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #Include <Constants.au3> #include ".\Skins\Hex.au3" #include ".\Skins\_UskinLibrary.au3" _Uskin_LoadDLL() _USkin_Init(_Hex(True)) Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Local $joy,$coor,$h,$s,$msg, $Tabbed = 0, $LetterCount = 0, $DeviceType = 0, $Gui Local $UseAsGamePad, $UseAsInput, $ActiveGui, $MapKeysGui, $SetKeysGui, $Action, $Shortcut Local $ActionSelector, $ShortcutButton, $KeyToMap, $ActionOrShortcut, $ShortcutToSave, $ShortcutInfo Global $KeyMaps $joy = _JoyInit() $Letters = IniReadSection(@ScriptDir & "\Data\Config.ini", "Letters") $ModeMenu = TrayCreateMenu("Mode") $GameModeItem = TrayCreateItem("Game Mode", $ModeMenu) TrayItemSetOnEvent(-1, "_GameMode") $PeripheralModeItem = TrayCreateItem("Peripheral Mode", $ModeMenu) TrayItemSetOnEvent(-1, "_PeripheralMode") TrayCreateItem("") $ShowGuiItem = TrayCreateItem("Display Controller Configuration") TrayItemSetOnEvent(-1, "_ShowGui") TrayCreateItem("") $ExitItem = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_Exit") TraySetState() _Gui() Func _GUI() $ActiveGui = "MainGui" $Gui = GuiCreate("Gamepad To Perpipheral..", 400,100) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGui") $UseAsGamePad = GuiCtrlCreateCheckbox("Enable game mode", 140,30) GUICtrlSetOnEvent(-1, "_GameMode") $UseAsInput = GuiCtrlCreateCheckbox("Enable peripheral device", 130, 60) GUICtrlSetOnEvent(-1, "_PeripheralMode") $MapKeysButton = GuiCtrlCreateButton("Map Keys", 300,40) GUICtrlSetOnEvent(-1, "_MapKeysGui") $ResetButton = GuiCtrlCreateButton("Reset Device", 25,40) GUICtrlSetOnEvent(-1, "_ResetDeviceSettings") GuiCtrlCreateLabel("An R.S.S. Product",150,10,200,20) GuiCtrlSetColor(-1, 0x3232ff) GuiSetState() EndFunc Func _ShowGui() GuiSetState(@SW_Show, $Gui) TrayItemSetState($ShowGuiItem, $TRAY_UNCHECKED) EndFunc Func _GameMode() $DeviceType = 0 GuiCtrlSetColor($UseAsGamePad, 0x00FF00) GuiCtrlSetColor($UseAsInput, 0xFFFFFF) GuiCtrlSetState($UseAsGamePad, $GUI_CHECKED) GuiCtrlSetState($UseAsInput, $GUI_UNCHECKED) TrayItemSetState($GameModeItem, $TRAY_CHECKED) TrayItemSetState($PeripheralModeItem, $TRAY_UNCHECKED) EndFunc Func _PeripheralMode() $DeviceType = 1 GuiCtrlSetColor($UseAsGamePad, 0xFFFFFF) GuiCtrlSetColor($UseAsInput, 0x00FF00) GuiCtrlSetState($UseAsGamePad, $GUI_UNCHECKED) GuiCtrlSetState($UseAsInput, $GUI_CHECKED) TrayItemSetState($GameModeItem, $TRAY_UNCHECKED) TrayItemSetState($PeripheralModeItem, $TRAY_CHECKED) EndFunc Func _MapKeysGui() $ActiveGui = "MapKeys" $MapKeysGui = GuiCreate("Key mapping..", 500,200) GuiSetBkColor(0x000000) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGui") GuiCtrlCreatePic(@ScriptDir & "\Images\Controller.bmp", 165,20) $UpMap = GuiCtrlCreateButton("Up",40,40, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapUp") $RightMap = GuiCtrlCreateButton("Right",80,80, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapRight") $DownMap = GuiCtrlCreateButton("Down",40,118, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapDown") $LeftMap = GuiCtrlCreateButton("Left",3,80, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapLeft") $LeftAnalogMap = GuiCtrlCreateButton("Left Analog (Designated)",45,170, 130, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $RightAnalogMap = GuiCtrlCreateButton("Right Analog (Designated)",310,170, 140, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $SelectMap = GuiCtrlCreateButton("Select",185,160, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapSelect") $StartMap = GuiCtrlCreateButton("Start",250,160, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapStart") $TriangleMap = GuiCtrlCreateButton("Triangle",380,40, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $CircleMap = GuiCtrlCreateButton("Circle",420,80, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapCircle") $XMap = GuiCtrlCreateButton("X",380,118, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $SquareMap = GuiCtrlCreateButton("Square",342,80, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_MapSquare") $L2Map = GuiCtrlCreateButton("L2",125,1, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $L1Map = GuiCtrlCreateButton("L1",125,35, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $R2Map = GuiCtrlCreateButton("R2",305,1, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $R1Map = GuiCtrlCreateButton("R1",305,35, 50, 30, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GuiCtrlSetColor(-1, 0xFF0000) $OkButton = GuiCtrlCreateButton("Close", 455,175,40,20, BitOr($BS_CENTER, $BS_DEFPUSHBUTTON)) GUICtrlSetOnEvent(-1, "_CloseGui") GuiSetState() EndFunc Func _SetKeysGui() $ActiveGui = "SetKeys" $SetKeysGui = GuiCreate("Set Keys..", 300,200) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGui") GuiCtrlCreateLabel("Map key as an action or a shortcut", 10,10, 400,30) GuiCtrlSetFont(-1,14) $ActionSelector = GuiCtrlCreateCombo("Copy",19,110,260,30) GUICtrlSetData(-1, "Cut|Paste|Browse Back|Browse Forward|Open My Computer|Close Current Window|Go To Desktop|Open Run..|Capslock|Windows Key|Escape|Space|Enter|Delete|Backspace") $ShortcutButton = GuiCtrlCreateButton("Browse...", 19,110,260,30) GUICtrlSetOnEvent(-1, "_OpenBrowse") GuiCtrlSetState($ActionSelector, $Gui_Hide) GuiCtrlSetState($ShortcutButton, $Gui_Hide) GuiCtrlCreateLabel("Current key to map", 80, 70,400,20) GuiCtrlSetFont(-1,12) $CurrentKey = GuiCtrlCreateLabel($KeyToMap, 130,90,400,20) GuiCtrlSetFont(-1,12) $ApplyButton = GuiCtrlCreateButton("Apply", 20,160,80,30) GUICtrlSetOnEvent($ApplyButton, "_Apply") $CancelButton = GuiCtrlCreateButton("Cancel", 190,160,80,30) GUICtrlSetOnEvent(-1, "_Cancel") $Action = GuiCtrlCreateCheckbox("Action", 40,50) GUICtrlSetOnEvent(-1, "_Action") $Shortcut = GuiCtrlCreateCheckbox("Shortcut", 200,50) GUICtrlSetOnEvent(-1, "_Shortcut") GuiSetState() EndFunc Func _Action() $ActionOrShortcut = "Action" GuiCtrlSetState($ActionSelector, $Gui_Show) GuiCtrlSetState($ShortcutButton, $Gui_Hide) GuiCtrlSetColor($Action, 0x00FF00) GuiCtrlSetColor($Shortcut, 0xFFFFFF) GuiCtrlSetState($Action, $GUI_CHECKED) GuiCtrlSetState($Shortcut, $GUI_UNCHECKED) EndFunc Func _Shortcut() $ActionOrShortcut = "Shortcut" GuiCtrlSetState($ActionSelector, $Gui_Hide) GuiCtrlSetState($ShortcutButton, $Gui_Show) GuiCtrlSetColor($Action,0xFFFFFF) GuiCtrlSetColor($Shortcut,0x00FF00) GuiCtrlSetState($Action, $GUI_UNCHECKED) GuiCtrlSetState($Shortcut, $GUI_CHECKED) EndFunc Func _CloseGui() If $ActiveGui = "MainGui" Then Sleep(10) GuiSetState(@SW_Hide, $Gui) ElseIf $ActiveGui = "MapKeys" Then GuiDelete($MapKeysGui) $ActiveGui = "MainGui" ElseIf $ActiveGui = "SetKeys" Then GuiDelete($SetKeysGui) $ActiveGui = "MapKeys" EndIf EndFunc Func _OpenBrowse() $ShortcutToSave = FileOpenDialog("Choose shortcut", @DesktopDir, "All (*.*)") If @error Then MsgBox(48, "Error", "No file selected, please select a file or press cancel!") EndIf EndFunc Func _Apply() $Confirm = MsgBox(4, "Confirm..", "Do you wish to apply the new key map?") If $Confirm = 6 Then If $ActionOrShortcut = "Action" Then $SaveAction = GuiCtrlRead($ActionSelector) If $SaveAction = "Copy" Then $SaveAction = "^c" ElseIf $SaveAction = "Cut" Then $SaveAction = "^x" ElseIf $SaveAction = "Paste" Then $SaveAction = "^v" ElseIf $SaveAction = "Browse Back" Then $SaveAction = "!{Left}" ElseIf $SaveAction = "Browse Forward" Then $SaveAction = "!{Right}" ElseIf $SaveAction = "Open My Computer" Then $SaveAction = "{LWindown}" & "e" & "{LWinUp}" ElseIf $SaveAction = "Close Current Window" Then $SaveAction = "^w" ElseIf $SaveAction = "Go To Desktop" Then $SaveAction = "{LWindown}" & "d" & "{LWinUp}" ElseIf $SaveAction = "Open Run.." Then $SaveAction = "{LWindown}" & "r" & "{LWinUp}" ElseIf $SaveAction = "Capslock" Then $SaveAction = "{CAPSLOCK}" ElseIf $SaveAction = "Windows Key" Then $SaveAction = "{LWin}" ElseIf $SaveAction = "Escape" Then $SaveAction = "{Escape}" ElseIf $SaveAction = "Space" Then $SaveAction = "{Space}" ElseIf $SaveAction = "Enter" Then $SaveAction = "{Enter}" ElseIf $SaveAction = "Delete" Then $SaveAction = "{Delete}" ElseIf $SaveAction = "Backspace" Then $SaveAction = "{Backspace}" EndIf IniWrite(@ScriptDir & "\Data\Config.ini", "KeyMaps", $KeyToMap, "A-" & $SaveAction) If @error Then MsgBox(48, "Error", "An error has occured..") EndIf ElseIf $ActionOrShortcut = "Shortcut" Then IniWrite(@ScriptDir & "\Data\Config.ini", "KeyMaps", $KeyToMap, "S-" & $ShortcutToSave) If @error Then MsgBox(48, "Error", "An error has occured..") EndIf EndIf _CloseGui() ElseIf $Confirm = 7 Then Sleep(100) EndIf EndFunc Func _Cancel() GuiDelete($SetKeysGui) $ActiveGui = "MapKeys" EndFunc Func _MapUp() $KeyToMap = "Up" _SetKeysGui() EndFunc Func _MapRight() $KeyToMap = "Right" _SetKeysGui() EndFunc Func _MapDown() $KeyToMap = "Down" _SetKeysGui() EndFunc Func _MapLeft() $KeyToMap = "Left" _SetKeysGui() EndFunc Func _MapSelect() $KeyToMap = "Select" _SetKeysGui() EndFunc Func _MapStart() $KeyToMap = "Start" _SetKeysGui() EndFunc Func _MapCircle() $KeyToMap = "Circle" _SetKeysGui() EndFunc Func _MapSquare() $KeyToMap = "Square" _SetKeysGui() EndFunc ;_____________________________________________________________________ while 1 If $DeviceType = 1 Then $coord=_GetJoy($joy,0) Local $KeyMaps = IniReadSection(@ScriptDir & "\Data\Config.ini", "KeyMaps") If @error Then MsgBox(48, "Error..", "An error occurred, probably no INI file.") EndIf ;~ _ArrayDisplay($coord, "test") If $coord[7] = "1" Then ; Triangle $MousePos = MouseGetPos() SplashOff() $CurrentLetterCount = $LetterCount $LetterCount = $CurrentLetterCount - 1 If $LetterCount > 67 Then $LetterCount = 0 ElseIf $LetterCount < 0 Then $LetterCount = 0 EndIf Sleep(200) SplashTextOn("", $Letters[$LetterCount][1], 40,40, $MousePos[0],$MousePos[1],BitOr(1,32), default,20) ElseIf $coord[7] = "2" Then ; Circle $CheckForActionOrShortcut = StringSplit($KeyMaps[7][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[7] = "4" Then ; X $MousePos = MouseGetPos() SplashOff() $CurrentLetterCount = $LetterCount $LetterCount = $CurrentLetterCount + 10 Sleep(200) If $LetterCount > 67 Then $LetterCount = 0 $CurrentLetterCount = 0 EndIf SplashTextOn("", $Letters[$LetterCount][1], 40,40, $MousePos[0],$MousePos[1],BitOr(1,32), default,20) ElseIf $coord[7] = "8" Then ; Square $CheckForActionOrShortcut = StringSplit($KeyMaps[8][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[7] = "16" Then ; L1 $MousePos = MouseGetPos() MouseClick("Left") Sleep(200) ElseIf $coord[7] = "64" Then ; L2 Sleep(10) For $i = 1 To 67 Step +1 If $LetterCount = $Letters[$i][0] Then Send($Letters[$i][1]) SplashOff() Sleep(200) ExitLoop EndIf Next $LetterCount = 0 ElseIf $coord[7] = "32" Then ; R1 $MousePos = MouseGetPos() MouseClick("Right") Sleep(500) ElseIf $coord[7] = "128" Then ; R2 $MousePos = MouseGetPos() If $LetterCount > 67 Then $LetterCount = 0 EndIf $LetterCount += 1 SplashTextOn("", $Letters[$LetterCount][1], 40,40, $MousePos[0],$MousePos[1],BitOr(1,32), default,20) Sleep(200) ElseIf $coord[7] = "512" Then ; Start Button $CheckForActionOrShortcut = StringSplit($KeyMaps[6][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[7] = "256" Then ; Select Button $CheckForActionOrShortcut = StringSplit($KeyMaps[5][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[6] = "27000" Then ; D-Pad Left $CheckForActionOrShortcut = StringSplit($KeyMaps[4][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[6] = "0" Then ; D-Pad Up $CheckForActionOrShortcut = StringSplit($KeyMaps[1][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[6] = "9000" Then ; D-Pad Right $CheckForActionOrShortcut = StringSplit($KeyMaps[2][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[6] = "18000" Then ; D-Pad Down $CheckForActionOrShortcut = StringSplit($KeyMaps[3][1], "-") If $CheckForActionOrShortcut[1] = "A" Then Send($CheckForActionOrShortcut[2]) Sleep(200) Else ShellExecute($CheckForActionOrShortcut[2]) Sleep(200) EndIf ElseIf $coord[1] = "0" Then ; Left Analog Up $MousePos = MouseGetPos() MouseMove($MousePos[0], $MousePos[1] - 4,1) ElseIf $coord[0] > "50000" Then ; Left Analog Right $MousePos = MouseGetPos() MouseMove($MousePos[0] + 4, $MousePos[1],1) ElseIf $coord[1] = "65535" Then ; Left Analog Down $MousePos = MouseGetPos() MouseMove($MousePos[0], $MousePos[1] + 4,1) ElseIf $coord[0] = "0" Then ; Left Analog Left $MousePos = MouseGetPos() MouseMove($MousePos[0] - 4, $MousePos[1],1) ElseIf $coord[3] = "0" Then ; Right Analog Up $MousePos = MouseGetPos() MouseMove($MousePos[0], $MousePos[1] - 15,1) ElseIf $coord[2] = "65535" Then ; Right Analog Right $MousePos = MouseGetPos() MouseMove($MousePos[0] + 15, $MousePos[1],1) ElseIf $coord[3] = "65535" Then ; Right Analog Down $MousePos = MouseGetPos() MouseMove($MousePos[0], $MousePos[1] + 15,1) ElseIf $coord[2] = "0" Then ; Right Analog Left $MousePos = MouseGetPos() MouseMove($MousePos[0] - 15, $MousePos[1],1) EndIf Else Sleep(10) EndIf 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 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 Func _ResetDeviceSettings() FileDelete(@ScriptDir & "\Data\Config.ini") FileCopy(@ScriptDir & "\Data\Backup Config.ini", @ScriptDir & "\Data\Config.ini") EndFunc Func _Exit() Exit EndFunc It has also been posted on SourceForge, the link is here It has all the images and ini files. A description is on the SourceForge/read me file. Thanks! Edited December 8, 2013 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic
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