Created
February 14, 2023 19:48
-
-
Save TheXenocide/379ccf40f3884e650c40e20039762382 to your computer and use it in GitHub Desktop.
Quick and dirty way to turn off numlock. One of my laptops doesn't have a numlock key but apparently still has logic to use the right side of the keyboard as a number pad so whenever it was disconnected from dock while numlock was still on could be annoying.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
if (Console.NumberLock) | |
{ | |
NativeMethods.SimulateKeyPress(NativeMethods.VK_NUMLOCK); | |
} | |
} | |
public static class NativeMethods | |
{ | |
public const byte VK_NUMLOCK = 0x90; | |
public const uint KEYEVENTF_EXTENDEDKEY = 1; | |
public const int KEYEVENTF_KEYUP = 0x2; | |
[DllImport("user32.dll")] | |
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); | |
public static void SimulateKeyPress(byte keyCode) | |
{ | |
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY, 0); | |
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment