Jump to content

Autohotkey Pedal To Keyboard Mapping


9 replies to this topic

#1 Kragg Relluf

    Member

  • PipPip
  • Overlord
  • 35 posts

Posted 19 September 2015 - 10:55 PM

Hi All -

I've got a set of flight pedals with toe brakes, and I thought it'd be fun to use those brakes to toggle controls, specifically jump jets and MASC.

So I managed to find an autohotkey script online that dealt with joysticks, and hack it to do what I want: it maps the toes (which are are analog devices like a joystick) to key presses. I'd not use autohotkey, but the pedals' programming software doesn't allow mapping key presses to the pedals.

It works well enough that when I go into the MWO keyboard settings, I can, for example, select MASC, and when I press one of the toes, the key I have mapped to it, 'P', is detected by MWO and entered as the setting for MASC. Same for jump jets - in the keyboard settings screen, MWO sees me hit the toe and detects the O key.

But, when I actually enter a match, MWO does not pick up the toe pedal presses (yes, everything is mapped correctly - I can press O or P on the keyboard, and the corresponding function activates).

Anyone with ideas? Here is the script:

EDIT: Things are working now. Here is the script in case someone is interested.
; Recommended for performance and compatibility with future AutoHotkey releases.
#NoEnv
 
; Enable warnings to assist with detecting common errors.
;#Warn
 
; This makes the "F12" key turn the script on and off as needed.
;F12::Suspend
 
; Recommended for new scripts due to its superior speed and reliability.
SendMode Input
 
; Ensures a consistent starting directory.
SetWorkingDir %A_ScriptDir%
 
#InstallKeybdHook
#SingleInstance force
 
; Set this to the pedals' Joystick number, as enumerated by windows.
joystickNumber = 1
 
; Threshold at which the a toe pedals' function will engage. That is
; if a toe pedal's position is greater than this, it will engage, less
; than this, it will disengage.
pedalPositionThreshold = 20
 
; These are set to true if on the previous trip through the loop
; the X or Y pedal was pressed past the threshold.
wasXPressed = 0
wasYPressed = 0
 
; These hold the position of the X and Y pedals on the current trip
; trip through the loop.
joyXPosition = 0
joyYPosition = 0
 
Loop
{
        ; Read state of pedals. Pedals seen as a joystick, with one toe brake as X axis, the
        ; other as Y axis. The main pedal function would be seen a "R" axis, I think, but it's
        ; not used here.
        GetKeyState, joyXPosition, %JoystickNumber%JoyX
        GetKeyState, joyYPosition, %JoystickNumber%JoyY
 
        ; If X axis pedal is pressed past the threshold, hold the specified key down.
        if joyXPosition > %PedalPositionThreshold%
        {
            Send, {o Down}
            wasXPressed = 1
        }
 
        ; If X axis pedal is released such that it is not past the threshold, release the key.
        if joyXPosition <= %PedalPositionThreshold%
        {
            ; Don't send the up key unless the pedal was pressed the last time through the loop.
            ; I.e don't send up unless the a down has been sent.
            if (wasXPressed == 1)
            {
                Send, {o Up}
                wasXPressed = 0
            }
        }
 
        ; If Y axis pedal is pressed past the threshold, hold the specified key down.
        if joyYPosition > %PedalPositionThreshold%
        {
            Send, {p Down}
            wasYPressed = 1
        }
 
        ; If Y axis pedal is released such that it is not past the threshold, release the key.
        if joyYPosition <= %PedalPositionThreshold%
        {
            ; Don't send the up key unless the pedal was pressed the last time through the loop.
            ; I.e don't send up unless the a down has been sent.
            if (wasYPressed = 1)
            {
                Send, {p Up}
                wasYPressed = 0
            }
        }
 
    ; Sleep for 100 ms every time through the loop.
    Sleep, 100
}
 
return
 

Edited by Kragg Relluf, 21 September 2015 - 03:31 PM.


#2 Davegt27

    Member

  • PipPipPipPipPipPipPipPipPipPip
  • Ace Of Spades
  • Ace Of Spades
  • 6,985 posts
  • LocationCO

Posted 19 September 2015 - 11:59 PM


I can’t even get the in game key map to work so I am no help

Did do a search one time and saw some info form the Dev Paul about using joy sticks

Did you try the search?


#3 Kragg Relluf

    Member

  • PipPip
  • Overlord
  • 35 posts

Posted 20 September 2015 - 02:03 PM

Thanks for the response. Yes, I've searched. it's not a joystick problem, really, but an autohotkey/mwo interaction problem.

Are you saying when you use the MWO keyboard settings to map keyboard keys, your settings for keyboard maps don't change the default key mappings? Or are you saying you're using autohotikey?

#4 Bulletsponge0

    Member

  • PipPipPipPipPipPipPipPipPip
  • The Vicious
  • The Vicious
  • 2,944 posts

Posted 20 September 2015 - 02:09 PM

View PostKragg Relluf, on 20 September 2015 - 02:03 PM, said:

Thanks for the response. Yes, I've searched. it's not a joystick problem, really, but an autohotkey/mwo interaction problem.

Are you saying when you use the MWO keyboard settings to map keyboard keys, your settings for keyboard maps don't change the default key mappings? Or are you saying you're using autohotikey?

I know my TS doesn't work in game unless I run it as an administrator.. and thats the extent of my technical abilities...lol

#5 Bilbo

    Member

  • PipPipPipPipPipPipPipPipPipPip
  • The Nimble
  • The Nimble
  • 7,864 posts
  • LocationSaline, Michigan

Posted 20 September 2015 - 02:13 PM

It seems to be a matter of finding what button the game thinks the tow switches are. Remap something with the in game key map to find out what it thinks those buttons are and adjust your ahk script accordingly. Probably not relevant, but my third mouse button has inexplicably become an arrow key according to the game.

#6 Kragg Relluf

    Member

  • PipPip
  • Overlord
  • 35 posts

Posted 20 September 2015 - 02:14 PM

So, it's something to do with the fact that the jump jet and MASC keys need to be held down (if you're using the non-toggle mode for MASC), and my script doesn't do this.

I modified the script to hold the jump jet key down, and I got jump jets to fire when pressing on the pedal. However, the change won't work for actually game play because it takes away control of when the key is released.

Anyway, I know there's a way to do this now, so I'll figure it out and post back for posterity once I have a working script.

#7 Kragg Relluf

    Member

  • PipPip
  • Overlord
  • 35 posts

Posted 20 September 2015 - 02:56 PM

View PostBilbo, on 20 September 2015 - 02:13 PM, said:

It seems to be a matter of finding what button the game thinks the tow switches are. Remap something with the in game key map to find out what it thinks those buttons are and adjust your ahk script accordingly. Probably not relevant, but my third mouse button has inexplicably become an arrow key according to the game.



Hi -
Thanks again for the response.

So since you tell the game what key should activate jump jets or MASC, you know that info, and that's what goes into the script. No need to figure that out. Problem was that even though the game saw the autohotkey output of O or P when the pedals were pressed while in MWO keyboard settings, when actually in a match, the game didn't seem to register the toe pedals.

But it WAS seeing them in match; the problem was that to operate jump jets or MASC, the game needs the keys to be held down. Thus, it would see a single O or P being pressed, but that wasn't enough to actually engage the JJs or MASC, or at least not enough time for the player to perceive they were engaged.

Thus, I modified the script to hold down the keys for as long as the pedals were pressed, and then to release the key once the pedals were released. Here is the working script, with lots of comments to show what's going on.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#InstallKeybdHook
#SingleInstance force
 
; Set this to the pedals' Joystick number, as enumerated by windows.
JoystickNumber = 1
 
; Threshold at which the a toe pedals' function will engage. That is
; if a toe pedal's position is greater than this, it will engage, less
; than this, it will disengage.
PedalPositionThreshold = 20
 
Loop
{
    IfWinActive, MechWarrior Online
    {
        ; Read state of pedals. Pedals seen as a joystick, with one toe brake as X axis, the
        ; other as Y axis. The main pedal function would be seen a "R" axis, I think, but it's
        ; not used here.
        GetKeyState, joyx, %JoystickNumber%JoyX
        GetKeyState, joyy, %JoystickNumber%JoyY

        ; If X axis pedal is pressed past the threshold, hold the specified key down.
        if joyx > %PedalPositionThreshold%
        {
           Send, {o Down}
        }

        ; If X axis pedal is released such that it is not past the threshold, release the key.
        if joyx <= %PedalPositionThreshold%
        {
           Send, {o Up}
        }

        ; If Y axis pedal is pressed past the threshold, hold the specified key down.
        if joyy > %PedalPositionThreshold%
        {
           Send, {p Down}
        }

        ; If Y axis pedal is released such that it is not past the threshold, release the key.
        if joyy <= %PedalPositionThreshold%
        {
           Send, {p Up}
        }
    }
	;Sleep for 100 ms every time through the loop.
	Sleep, 100
}
 
return

Edited by Kragg Relluf, 20 September 2015 - 04:16 PM.


#8 SolCrusher

    Member

  • PipPipPipPipPipPipPip
  • The 1 Percent
  • The 1 Percent
  • 611 posts
  • LocationEast Coast

Posted 20 September 2015 - 03:06 PM

You may need to add some of this so it will focus on the MWO window.


#InstallKeybdHook
#InstallMouseHook

;These next 2 lines make it so the script is only active within the mechlab and match window
#IfWinActive, ahk_class CryENGINE
#IfWinActive MechWarrior Online

F12::Suspend ;This makes the "F12" key turn the script on and off as needed.

Edited by SolCrusher, 20 September 2015 - 03:07 PM.


#9 Kragg Relluf

    Member

  • PipPip
  • Overlord
  • 35 posts

Posted 20 September 2015 - 04:17 PM

View PostSolCrusher, on 20 September 2015 - 03:06 PM, said:

You may need to add some of this so it will focus on the MWO window.


#InstallKeybdHook
#InstallMouseHook

;These next 2 lines make it so the script is only active within the mechlab and match window
#IfWinActive, ahk_class CryENGINE
#IfWinActive MechWarrior Online

F12::Suspend ;This makes the "F12" key turn the script on and off as needed.



Was just coming back to add the ifwinactive stuff, but didn't know about the F12, so thanks!

#10 Kragg Relluf

    Member

  • PipPip
  • Overlord
  • 35 posts

Posted 20 September 2015 - 04:23 PM

View PostSolCrusher, on 20 September 2015 - 03:06 PM, said:

You may need to add some of this so it will focus on the MWO window.


#InstallKeybdHook
#InstallMouseHook

;These next 2 lines make it so the script is only active within the mechlab and match window
#IfWinActive, ahk_class CryENGINE
#IfWinActive MechWarrior Online

F12::Suspend ;This makes the "F12" key turn the script on and off as needed.



When I put that these items in, the script stops working to varying degreess depending on what I put in. If I put the suspend f12 item in, I can stop and start the script, but I get no key presses (even in a text editor) when I press the pedals. I'm gonna just go with what I have and deal with it for now because I'd like to get playing. I'll have to revisit to get the rest working. Thanks everyone for help.

Edited by Kragg Relluf, 20 September 2015 - 04:32 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users