Permanently Enable Number Lock on Windows Via Script

Last Updated on

Number lock – I prefer it on.  In fact, I cannot recall a situation in which I have ever needed to actually turn it off – my interactions with the key are always relegated to ensuring the light is illuminated on the keyboard.  As a result, I wrote this simple script that more or less ensures number lock will remain on.  It’s somewhat useful to eliminate this nuisance and is also relatively handy when working with virtual machines.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Global Const $VK_NUMLOCK = 0x90
Global Const $VK_SCROLL = 0x91
Global Const $VK_CAPITAL = 0x14

ConsoleWrite(_GetNumLock() & @LF)
ConsoleWrite(_GetScrollLock() & @LF)
ConsoleWrite(_GetCaps() & @LF)
#include $x=1

AutoItSetOption ( "TrayMenuMode" , 1 )
TraySetToolTip ("Numlock LOCK")

Do
sleep(30000)

consolewrite(_GetNumLock() & @CR)
if _GetNumLock() = 0 then

send("{NUMLOCK}")

EndIf

until $x=2

Func _GetNumLock()
Local $ret
$ret = DllCall("user32.dll","long","GetKeyState","long",$VK_NUMLOCK)
Return $ret[0]
EndFunc

Func _GetScrollLock()
Local $ret
$ret = DllCall("user32.dll","long","GetKeyState","long",$VK_SCROLL)
Return $ret[0]
EndFunc

Func _GetCaps()
Local $ret
$ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPITAL)
Return $ret[0]
EndFunc

Download Compiled Scripts as EXE

Grab a Copy of AutoIT

Lima

About the author

Lima is the visual nautical indicator for "stop instantly."

Leave a Reply