Hotkey script able to disable another script.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SebKat
Posts: 3
Joined: 01 Feb 2023, 05:16

Hotkey script able to disable another script.

Post by SebKat » 01 Feb 2023, 23:21

Currently i use 2 separate scripts to make "F" and "SHIFT" keys work as Toggle keys:

Code: Select all

*f::
    if GetKeyState("f")
        Send {Blind}{f Up}
    else
        Send {Blind}{f Down}
return

F1::Suspend, Toggle
F3::ExitApp

Code: Select all

*LShift::
    if GetKeyState("LShift")
        Send {Blind}{LShift Up}
    else
        Send {Blind}{LShift Down}
return

F2::Suspend, Toggle
F4::ExitApp
My goal is to merge both scripts into ONE script and as the title states to be able to disable one key toggled when the other key toggle activates, in other words: if TOGGLE SHIFT -> ON when I press F to TOGGLE F -> SHIFT ON goes OFF.

I'm quite new to AHK and can't seem to find the correct way to make it work, any help is greatly appreciated.

Rohwedder
Posts: 7608
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey script able to disable another script.

Post by Rohwedder » 02 Feb 2023, 02:34

Hallo,
perhaps ??:

Code: Select all

HF := HLShift := True
Return
*f::
	Hotkey, *LShift, Off ;Switches Hotkey *LShift off
	HLShift := False
    if GetKeyState("f")
        Send {Blind}{f Up}
    else
        Send {Blind}{f Down}
return
F1::Hotkey, *f,% (HF:=!HF)?"On":"Off" ;Toggles Hotkey *f
F3::ExitApp

*LShift::
	Hotkey, *f, Off ;Switches Hotkey *f off
	HF := False
    if GetKeyState("LShift")
        Send {Blind}{LShift Up}
    else
        Send {Blind}{LShift Down}
return
F2::Hotkey, *LShift,% (HLShift:=!HLShift)?"On":"Off" ;Toggles Hotkey *LShift
F4::ExitApp

SebKat
Posts: 3
Joined: 01 Feb 2023, 05:16

Re: Hotkey script able to disable another script.

Post by SebKat » 03 Feb 2023, 00:54

Rohwedder wrote:
02 Feb 2023, 02:34
Hallo,
perhaps ??:

Code: Select all

HF := HLShift := True
Return
*f::
	Hotkey, *LShift, Off ;Switches Hotkey *LShift off
	HLShift := False
    if GetKeyState("f")
        Send {Blind}{f Up}
    else
        Send {Blind}{f Down}
return
F1::Hotkey, *f,% (HF:=!HF)?"On":"Off" ;Toggles Hotkey *f
F3::ExitApp

*LShift::
	Hotkey, *f, Off ;Switches Hotkey *f off
	HF := False
    if GetKeyState("LShift")
        Send {Blind}{LShift Up}
    else
        Send {Blind}{LShift Down}
return
F2::Hotkey, *LShift,% (HLShift:=!HLShift)?"On":"Off" ;Toggles Hotkey *LShift
F4::ExitApp


Edit: I re-tried the script and it actually does work but my goal was another, let me explain: i need to make one hotkey cancel the other hotkey (or at least let the other ficical key up. Eg: [F: ON --> SHIFT: OFF / SHIFT: ON --> F: OFF) so that both hotkeys are not toggled ON at the same time when i use one then the other.

SebKat
Posts: 3
Joined: 01 Feb 2023, 05:16

Re: Hotkey script able to disable another script.

Post by SebKat » 03 Feb 2023, 01:55

I've managed to find how to do it simple added the State Up o the hotkey as an extra command and now it work as i wanted, thanks for the help!

Post Reply

Return to “Ask for Help (v1)”