0
votes

I've been searching for quite a while and took a look at alot of documentation on AHK, but haven't quite found out how to do this.

So basically, anytime CTRL + another key is pressed, I want to check what the other key is. When the other key is not one of the numpad numbers, I want to only send the other key. When the key is one of the numpad numbers, I want to send CTRL and the numpad key.

Thanks in advance!

1
What did you try so far? - Dieter Meemken
Took a look at 'Input', but didn't quite figure it out. If there's a way to detect when any key is pressed and retrieve which key it is, I could solve it. However, I am unable to find how to do this. - rrrR
What do you want to achieve? What combinations of keys do you want catch exactly? E.g. Ctrl + Shift + Numpad0? Or Ctrl + a + s? - MCL
I dont really understand the downvotes. The question is clear and surely not trivial. - phil294

1 Answers

0
votes

I can only think of two ways. Firstly, assigning every hotkey manually.

loop, 255 {
    char := chr(a_index - 1)
    try {
        hotkey, ^%char%, send_key, char
    } catch e { 
        ; many keys in the ansi chart cant be assigned to a hotkey, just ignore the error
    }
}
return
send_key:
    ; A_ThisHotkey contains the pressed combination in a format like ^C. Remove the ^
    key := subStr(a_thisHotkey, 2)
    sendraw %key%
return

The loop iterates over all ANSI characters. See https://msdn.microsoft.com/en-us/library/aa245259(v=vs.60).aspx for a list. It is only a short form for

^a::send a
^b::send b

etc., 255 times. This approach doesn't affect space, numpad numbers (which you want), # and many more, and it also cannot differentiate between lowercase and uppercase letters. But maybe it'll do for you.

Secondly, using input. Read the doc page about it and if you still struggle, edit your question I guess. I don't know if or how this will work for key combinations