Very recently, I stumbled across Autohotkey. I decided I'd like to try using it to map my Logitech F310 controller's outputs to keyboard input for Lone Survivor. It was a little easier than I thought, given I've had no experience making scripts. Now I want to improve this script. What suggestions does the rest of the community have for this first-time try? Don't forget to rename this to .ahk once you've checked it out into a file. Disclaimer: I've also posted this to autohotkey.com forums, before I found out about this website and forum.
Spoiler
; Created by brickviking, Flying Brick Systems (C) 2014
; You may freely use and adapt this script to your own needs, but please
; don't try to make money from it. Heck, it's a script.
; A simple script for Lone Survivor game
; Adjust to suit your own joystick/controller, I used a Logitech F310 in Xinput mode
; Works with AHK 1.0.48.5 and 1.1.16.05
#Persistent ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 5
return
WatchAxis:
GetKeyState, JoyX, JoyX ; Get position of X axis.
GetKeyState, JoyY, JoyY ; Get position of Y axis.
GetKeyState, JoyPOV, JoyPOV ; Get POV
KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
if JoyX > 70
KeyToHoldDown = Right
else if JoyX < 30
KeyToHoldDown = Left
else if JoyY > 70
KeyToHoldDown = Down
else if JoyY < 30
KeyToHoldDown = Up
; POV-Hat
else if JoyPOV = 27000 ; POV-left
KeyToHoldDown = 1 ; Flare
else if JoyPOV = 0 ; POV-Up
KeyToHoldDown = 2 ; Meat
else if JoyPOV = 9000 ; POV-Right
KeyToHoldDown = 3 ; Health Potion
else if JoyPOV = 18000 ; POV-Down
KeyToHoldDown = R ; Reload
else
KeyToHoldDown =
if KeyToHoldDown = %KeyToHoldDownPrev% ; The correct key is already down (or no key is needed).
return ; Do nothing.
; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1 ; Avoid delays between keystrokes.
if KeyToHoldDownPrev ; There is a previous key to release.
Send, {%KeyToHoldDownPrev% up} ; Release it.
if KeyToHoldDown ; There is a key to press down.
Send, {%KeyToHoldDown% down} ; Press it down.
return
; JoyBtn, {Key}
Joy3::Send {X} ; Action (Interact/Shoot), X
Joy5::Send {F} ; Flashlight, Left Shoulder
Joy6::Send {M} ; Map, Right Shoulder
Joy8::Send {Escape} ; Menu, Start
Joy9::Send {C} ; Weapon, Left stick click
Joy10::Send {Space} ; Inventory, Right stick click
; other keys that can be set.
Joy1::Send {S} ; Gamma -, Y button
; Joy2::Send {B} ; B button
Joy4::Send {A} ; Gamma +, A button
; End of script