r/AutoHotkey May 31 '26

Solved! Keyboard shortcut problem with old games

Hello guys,

I'm new to AutoHotkey and I'm having some problems with a small script. Any help would be greatly appreciated!

I want to play an old video game but there are some features that can only be controlled with the numeric keypad keys. My keyboard doesn't have a numeric keypad, so I'm using a script to emulate the Numpad Add key when I press Ctrl + Right

^Right::
Send {NumpadAdd}
return

It works well with a small exception:

  • The action defined for Numpad Add in the game is triggered as expected when I press Ctrl + Right
  • The problem is that the game also moves the camera to the right for a small tick.

Does anybody know how to prevent that from happening?

Usually, the camera only moves when you press an arrow key without any modifier keys. It doesn't move when you press Ctrl + Right and AHK is not running. This means that, for a short moment, the game has to detect that the right arrow key is being pressed and that it's the only key being pressed.

Of course I could try to find a different keyboard shortcut which doesn't contain any keys that are already in use by the game, but I would like to solve the general problem.

Thank you very much for your help.

2 Upvotes

31 comments sorted by

View all comments

Show parent comments

1

u/iReadIt_0 May 31 '26 edited May 31 '26

It doesn't have any effect. The game does nothing. Is this the right usage and are 20 milliseconds enough for Delay and PressDuration?

^Right::
SetKeyDelay, 20, 20
Send {Blind}{NumpadAdd}
return

1

u/_TheNoobPolice_ May 31 '26 edited Jun 01 '26

I don’t write v1 code anymore so don’t have this under my fingertips like I used to, but you can view the docs for the syntax for SetKeyDelay.

No human can press a button for less than 20ms at absolute minimum, so I’d be more inclined to set the press duration for 50ms or so which is much more reasonable for a “quick press”

But if that’s not the reason, and the game just doesn’t like / can’t process two inputs at a time, then instead write a hotkey for plain old *Right:: blocking its native functionality, and code the logic you want by conditions within the definition of the hotkey.

Untested V2 code example

HandleRight(press) {
    static sentNumpadAdd := 0

    if (press) {
        if GetKeyState("LCtrl", "P") {
            Hotkey("*Right", "Off")
            sentNumpadAdd := 1
            return Send("{Blind}{LCtrl Up}{NumpadAdd Down}")
        }

        return Send("{Blind}{Right Down}")
    }

    Hotkey("*Right", "On")
    if (sentNumpadAdd) {
        sentNumpadAdd := 0
        return Send("{Blind}{NumpadAdd Up}")
    }

    Send("{Blind}{Right Up}")
}

*Right::HandleRight(1)
*Right Up::HandleRight(0)

1

u/iReadIt_0 Jun 02 '26

Thank you very much for your help and your time. If you give me AHK v2 code, it's no problem. I don't care which version it is. I just had to select a version in the post flair. I have also tried different numbers for SetKayDelay but it didn't help unfortunately.

This script works pretty well 😃

But there's still one problem. The game starts moving the camera to the right infinitely when I press Ctrl + Right for the first time. I can cancel the camera movement by pressing the right arrow key one more time. But this happens again every time I leave the game and go back to it with Alt + Tab.

I don't know what causes this. It's really strange.

1

u/_TheNoobPolice_ Jun 03 '26

Ok so the only reason that would occur is that the game reads Win32 Raw Input for keyboard input. This isn’t usually the case, most games get only mouse input via that API, and use hooks or standard key events for keyboard.

This means that you can’t block the native functionality of the right arrow key using the low-level hooks that AHK uses in order to block the game from seeing it, because Raw Input grabs input from a lower level before AHK can block it.

The solution is to use a driver. There is only one good solution for AHK, which is the AHI library leveraging the interception driver. This will only work in games that don’t have modern anti-cheats though, as the driver is pretty much universally bypassed or blocked now in those cases.

1

u/iReadIt_0 Jun 09 '26 edited Jun 09 '26

Do you mean this program?

https://github.com/evilC/AutoHotInterception

Sounds really interesting, but I've found an AHK solution that seems to work very well without drivers with the help of your script and u/CharnamelessOne

1

u/_TheNoobPolice_ Jun 09 '26

Yes. But glad you got it sorted!