Problem sending Win+A_PriorKey

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
afshindavoudy
Posts: 44
Joined: 10 Jan 2024, 13:25

Problem sending Win+A_PriorKey

Post by afshindavoudy » 01 Feb 2024, 08:03

I have this modified version of Morse Function by Laszlo, which detects different patterns of pressing Win key (Single, double or triple in addition to short and long presses)

Code: Select all

Morse(Timeout := 150, Count := 3)
{
    Global Pattern := ""
    Win := WinExist("A")
    RegExMatch(Hotkey := A_ThisHotkey, "\W$|\w*$", &Key)
    CoordMode("Mouse", "Screen")
    MouseGetPos(&X1, &Y1, &Win1)

    Loop (Count) {
        T := A_TickCount
        ErrorLevel := !KeyWait(Key[0])
        Pattern .= A_TickCount - T > Timeout
        ErrorLevel := !KeyWait(Key[0], "DT" Timeout / 1500)
        MouseGetPos(&X2, &Y2, &Win2)
        ; Skip the operation for Win key if another key pressed!
        IF (InStr(Hotkey, "Win") And (Win Key[0] Hotkey Win1) != (WinExist("A") A_PriorKey A_ThisHotkey Win2))
        {
            SendInput("{LWin Down}" A_PriorKey "{LWin Up}") ; Sending the key combination to OS to run
            Exit
        }
        If ErrorLevel
            return Pattern
    }
}

LWin::
{
    hotkey := SubStr(A_ThisHotkey, 2)
    Patterm := Morse()
    Switch Patterm
    {
        Case "0":
            MsgBox(hotkey " " Patterm)
        Case "1":
            MsgBox(hotkey " " Patterm)
        Default:
            MsgBox(hotkey " " Patterm)
    }
    Return
}
When I for example press Win+e, I need the script to send LWin+e key combo to OS (to open the Explorer) then exits the function, which it does already. But in the text base environments like MSWord, it also types a letter e also.

I don't know how to prevent that.
Appreciate any help
Last edited by afshindavoudy on 01 Feb 2024, 08:17, edited 2 times in total.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Problem sending Win+A_PriorKey

Post by mikeyww » 01 Feb 2024, 08:14

Hello,

It sounds like you want to block the key's native function for E. This is typically done with a hotkey for that key, a custom combination, or an InputHook.

If you call the Send function to send a key that is also a hotkey in your script, your function call may trigger that hotkey. When needed, this can be prevented by using the $ prefix.

Although AHK v2 uses SendInput by default, in some situations, SendEvent is a better choice.

A main issue to determine is whether you see "e" because your script sends it or because your script ignores it (leaving your manual keyboarding intact).

Post Reply

Return to “Ask for Help (v2)”