Create Toggle Switch When Double Pressing Hotkey Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
antoniopap
Posts: 3
Joined: 28 Nov 2022, 23:05
Contact:

Create Toggle Switch When Double Pressing Hotkey

Post by antoniopap » 29 Nov 2022, 15:33

In the code below I am trying to cycle between two actions, Msgbox "enabled" and Msgbox "disabled." I have the variable keyboardLighting set to false when starting the script (global variable). When double pressing right control, it will only run the action "msgbox disabled." How can I fix this?

Code: Select all

~RControl:: ; Right Control Pressed Twice Quickly
    KeyWait, RControl
    KeyWait, RControl, D T0.2
    if ErrorLevel
      Send single
    Else {
      if (keyboardLighting == false)
        MsgBox, "Enabled"
      else 
        MsgBox, "Disabled"
      }
    keyboardLighting := !keyboardLighting 
Return

sofista
Posts: 650
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Create Toggle Switch When Double Pressing Hotkey

Post by sofista » 29 Nov 2022, 16:28

Use the case-insensitive equal (=), instead of the case-sensitive equal (==), so try:

Code: Select all

if (keyboardLighting = false)
As an alternative:

Code: Select all

if !keyboardLighting

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

Re: Create Toggle Switch When Double Pressing Hotkey  Topic is solved

Post by Rohwedder » 29 Nov 2022, 16:46

Hallo,
try:

Code: Select all

~RControl:: ; Right Control Pressed Twice Quickly
KeyWait, RControl
KeyWait, RControl, D T0.2
if ErrorLevel
	Send single
Else if keyboardLighting := !keyboardLighting
	MsgBox, "Enabled"
else
	MsgBox, "Disabled"
Return

Post Reply

Return to “Ask for Help (v1)”