0
votes

Background: I'm trying to have a f-mode and d-mode which means if I press down the f key and press another key like i then nothing happens excepts a shortcut. let say it will send Up key instead of f and I. Issue: how I can remap a pressed key (I in my example) to a shortcut (Up as example)?

Code:

d::
    f::{
        ;...
        loop{
            if !GetKeyState("f","p") && !GetKeyState("d","p"){
                break
            }
            if GetKeyState("i","p") {
                OutputDebug "i"
                send "{up}"
                continue
            }
            ; ...
      }
}
1

1 Answers

0
votes

Looks like you want to make a custom combination.

From the Docs:

You can define a custom combination of two keys (except joystick buttons) by using " & " between them. In the below example, you would hold down Numpad0 then press the second key to trigger the hotkey:

Numpad0 & Numpad1::MsgBox You pressed Numpad1 while holding down Numpad0.
Numpad0 & Numpad2::Run Notepad

But also note:

The prefix key loses its native function: In the above example, Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its original/native function when it is pressed by itself. To avoid this, a script may configure Numpad0 to perform a new action such as one of the following:

Numpad0::WinMaximize A   ; Maximize the active/foreground window.
Numpad0::Send {Numpad0}  ; Make the release of Numpad0 produce a Numpad0 keystroke. See comment below.

This is to prevent holding down a key from spamming inputs while you wait to press the second part of a key combination. So essentially, your 'f' and 'd' keys will now perform their normal functions when you release them instead of initially pressing them down.


Anyways, the code would become:

f & i::
d & i::
Send {Up}
return

f::f
d::d