autohotkeyautohotkey-2

How to not chain a hotkey's output to another hotkey?


I'm currently trying to map some shortcuts to better match my windows keyboard shortcuts to those similar of a mac.

Windows Powertoys is an option, but I'd really like to understand how to get this working properly on autohotkeys, as I have other hotkeys and mapping already set up and Powertoys was a bit glitchy at times.


It's almost working how I want it to, except for trying to map the Alt+arrow_keys to Win+arrow_keys.

The goal is the be able to use Alt+arrow_keys to move current windows around, but since Win+arrow_keys are also mapped, the result is just whatever the Win+arrow_keys are mapped to

This is what I have so far

#Requires AutoHotkey v2.0
#SingleInstance Force

/*
    Alt + Left  --> Win + Left
    Alt + Right  --> Win + Right
    Alt + Up  --> Win + Up
    Alt + Down --> Win + Down
*/
$!Left:: SendInput "#{Left}"
$!Right:: SendInput "#{Right}"
$!Up:: SendInput "#{Up}"
$!Down:: SendInput "#{Down}"

/*
    Win + Left --> Ctrl+Left
    Win + Right --> Ctrl+Right
    Win + Up --> Up
    Win + Down --> Down
*/
$#Left::Send "^{Left}"
$#Right::Send "^{Right}"
$#Up::Send "{Up}"
$#Down::Send "{Down}"

/*
    Ctrl + Left --> Home
    Ctrl + Right --> End
    Ctrl + Up --> Page Up
    Ctrl + Down --> Page Down
*/
$^Left::Send "{Home}"
$^Right::Send "{End}"
$^Up::Send "{PgUp}"
$^Down::Send "{PgDn}"

;   Win + Shift + Left  --> Ctrl + Shift + Left
;   Win + Shift + Right --> Ctrl + Shift + Right
$#+Left::Send "^+{Left}"
$#+Right::Send "^+{Right}"


;   Ctrl + Shift + Left  --> Shift + Home
;   Ctrl + Shift + Right --> Shift + End   
$^+Left::Send "+{Home}"
$^+Right::Send "+{End}"

I have tried to use suspend to stop the other hotkeys from working for the duration of the hotkey press, but it didn't still didn't seem to work.

#SuspendExempt
!Left:: {
    Suspend 1 ; Suspend other hotkeys
    Send "#{Left}"  ; Send what I actually want
    Sleep(50) ; tried both w/ and w/out the delay to see if it would help.
    Suspend 0 ; Unsuspend the hotkeys
}
!Right:: {
    Suspend 1
    Send"#{Right}"
    Suspend 0
}
!Up:: {
    Suspend 1
    Send"#{Up}"
    Suspend 0
}
!Down:: {
    Suspend 1
    Send"#{Down}"
    Suspend 0
}
#SuspendExempt False

I have also tried using $ and ~, but those didn't work either.


Solution

  • Mask issue / conflict with WIN/CTRL/ALT

    No you mix it up, this isn't map this just hock the key combination and mimic sending key stroke since you are using send() it doesn't link to other hotkeys have you tried send({LWin down}{Left}{Lwin UP})?

    if above doesn't work generally the reason why is some satiation AHK try to do mask win / alt key with fake key event with Mask key

    My prefer method (registry + AHK)

    you better bind your win to f13-f24 via registry like sharepkey and after that bind win key from f13 I use this mothed for 1+ year and I'm happy with it.

    Note: not all software support f13-f24 but you can use AHK to do another shortcut for specific software.