r/AutoHotkey • • Oct 28 '26

v2 Script Help How tf does a program differentiate between AHK input and physical Keyboard

I have been playing around with macros and scripts for a bit for fun, and something I've noticed is that some games (Specifically AION2 right now) Will detect when AHK is running a macro somehow and ignore the input, however, both Corsair and Logitech software macros run as if I was truly physically pressing the buttons and are not ignored.

Normally This is just fine but I've recently wanted to expand into making more in depth macros and felt AHK2 was the best way to do this, such as using ControlSend to be able to tab out and do homework when i otherwise would be holding down 2 buttons staring at the screen to kill mobs and loot. I would not consider this cheating as 1:The entire community already has macros like this set up, and 2: the game already has an in built macro function, its just a bit simple.

As an example, I have a macro that presses F a lot because you need to press F to loot items. AHK works just fine sending thru almost any send function, however only to chat. As soon as I close chat the game no longer takes the input.

This is genuinely very interesting to me and I've been on a rabbit hole reading but I'm not sure where to start.
My question is, how would a program even go about detecting the difference in inputs like this? From AHK to my physical keyboard and Corsair/Logitech macro software. I am willing to learn if its complicated, and I would like to "simulate" hardware input or do whatever logitech does, if that's possible.

9 Upvotes

8 comments sorted by

9

u/evanamd Oct 28 '26

You may also want to read microsoft's overview of keyboard input: https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input

But the most basic answer to your question is that physical keyboard inputs come from a lower system level than software like ahk, which has to inject them through an api

3

u/ilanxya Oct 28 '26

People here know stuff dudeeeee that is rabbit holee

11

u/CharnamelessOne Oct 28 '26 edited Oct 28 '26

Sometimes, all you need to do is run the .ahk script as admin, and/or make sure that the keys sent by AHK are "held" down for a couple dozen milliseconds, otherwise the input may get lost between keyboard polls.

If the game uses raw input, AHK-sent inputs (which are generated via the WinApi functions called SendInput and keybd_event) will be ignored.
You can use AutoHotInterception to generate inputs at the driver level, which may work on games using raw input, but games using kernel-level anti-cheat are likely to detect the Interception driver.

It's not uncommon for games to use a different way of detecting inputs when you are in a menu/text field. Sometimes, they will use raw input for the mouse, but not for the keyboard.

You may also consider reading the following guide by Descolada if you're really interested: Adventures of a keystroke

5

u/JacobStyle Oct 28 '26 edited Oct 28 '26

I don't know for this game in particular, but I have seen that some games do not work well with the standard AHK functions, not because they are intentionally blocking them, but because they just don't detect the AHK keystrokes properly. AHK 2.0 supports different send modes and other options, and getting macros to work with any given game may require fiddling around with these to find something that works. For example, I have had ones where I had to send the keydown event, then a delay, then the keyup event, as separate lines to get the game to accept the input.

edit: forgot to include the link to the relevant documentation: https://www.autohotkey.com/docs/v2/lib/Send.htm

3

u/luigislam Oct 28 '26

Doing a quick google search and I'm immediately seeing that you're gonna get yourself banned using AHK on Aion2 for gaslighting yourself into thinking you're okay to do so when there's clear signs that you shouldn't be doing that lmao.

Anyway in simple terms that is not 100% correct, inputs are tracked with information that can be used to figure out where it came from which is used by Kernel Level Anti-Cheat to know if its simulated/physical. The anti-cheat is the first thing that sees the input before anything else does which stops you from trying to fake the simulated keystroke which is also why everyone just resorts to macros on a keyboard/mouse because the anti-cheat only sees whats on your computer and not what your keyboard/mouse is doing other than the fact that it just sent physical inputs.

2

u/throwaway214203 Oct 28 '26

Look into running it through a raspberry pi to emulate the hardware (haven’t done this, just know people do)

2

u/SenzLord Oct 28 '26

Um... What is that called virtual input? I believe this is the case.

1

u/delacroix01 Nov 02 '26

Try running AHK with admin privilege. Recently I had to do that with Dynasty Warriors 3 Remastered since the game somehow doesn't recognize my DualShock 1 controller, not even with Steam Input, and AHK was the only way I can use my controller to play the game.