how to use Numlock with KeyWait

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

how to use Numlock with KeyWait

28 Oct 2021, 02:54

This my current Numlock:

Code: Select all

Gosub, ~NumLock
SoundPlay, ""
Return

~NumLock::
			NNLState := !GetKeyState("NumLock","T")					;[Basis] ➤ Numlock Toggle
			GetKeyState, NumState, NumLock, T
			If NumState = D
			{
			Sleep, 150
			SoundPlay, C:\AutoHotkey\AutoHotkey - Sound\Single_isolated_beacon (high).wav
			Progress, B1 fs9 zh0, `nNumlock State is toggled On.`n`nPress 'Numlock' to default.`n, ,Numlock State, Segoe UI
			}
			else
			{
			Sleep, 150
			SoundPlay, C:\AutoHotkey\AutoHotkey - Sound\Single_isolated_beacon (low).wav
			Progress, Off
			}
			return

I have many other hotkeys with KeyWait, 'key-name', T0.2: only triggers after key is hold down for T0.2.

Im just wondering, if its possible to apply it to Numlock?

Below was just for a try.

Code: Select all

Gosub, ~NumLock
SoundPlay, ""
Return

~NumLock::
			KeyWait, NumLock, T0.2 							       ;[Basis] ➤ Numlock Toggle
			If (ErrorLevel) 
 				{
				NNLState := !GetKeyState("NumLock","T")					
				GetKeyState, NumState, NumLock, T
				If NumState = D
					{
					Sleep, 150
					SoundPlay, C:\AutoHotkey\AutoHotkey - Sound\Single_isolated_beacon (high).wav
					Progress, B1 fs9 zh0 W210, `nNumlock State is toggled On.`n`nPress 'Numlock' to default.`n, ,Numlock State, Segoe UI
					}
				else
					{
					Sleep, 150
					SoundPlay, C:\AutoHotkey\AutoHotkey - Sound\Single_isolated_beacon (low).wav
					Progress, Off
					} 													
				KeyWait, NumLock
 				}
			else 
				{
				Progress, B1 ZH0 fs9 H25 W110 CWFFFFFF, Cut to clipboard, , , Segoe UI	;~	
				Sleep, 600
				Progress, Off	
				}											
			return	
I know this is not right : ( , it's just too complex for me.
I tried several other arrangements, but can't get it to work.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: how to use Numlock with KeyWait

28 Oct 2021, 04:11

Code: Select all

~NumLock::
    KeyWait, NumLock, T0.2
    if (ErrorLevel)
    {
        if (GetKeyState("NumLock","T") = true)
        {
            MsgBox, 4096, % "ErrorLevel = " . ErrorLevel,  % A_ThisHotkey . " was pressed down for: " . A_TimeSinceThisHotkey . "`nToggle = true"
        }
        else
        {
            MsgBox, 4096, % "ErrorLevel = " . ErrorLevel,  % A_ThisHotkey . " was pressed down for: " . A_TimeSinceThisHotkey . "`nToggle = false"
        }
    }
    else
    {
        MsgBox, 4096, % "ErrorLevel = " . ErrorLevel, % A_ThisHotkey . " was pressed down for: " . A_TimeSinceThisHotkey
    }
return
s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: how to use Numlock with KeyWait

29 Oct 2021, 03:32

Hi Extra, thank you very much for the response.
I tried your script, but the Numlock triggers 'Numlock' even without holding for T0.2.

I read somewhere.. it says there is a bug for the these numlock capslock configurations.
I was just curious. perhaps it is a bug.
There is nothing impossible to him who will try. -Alexander the Great-
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: how to use Numlock with KeyWait

29 Oct 2021, 05:45

To block the key's native function, remove the tilde from the hotkey.

Explained: Tilde

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, Google [Bot], RandomBoy, Rohwedder and 352 guests