Set num lock?
Hi,
I have a rather simple question that I can't seem to find the answer to, but is it possible to set the status of the num lock in a Windows application?
Thanks.
Weiran.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Darren Marshall17 pointsPosted May 29, 2006, 8:41 PM EDT
I found this post: http://www.codecomments.com/archive290-2005-5-489956.html
I tried it and it works, all you need to do is...
1. libs:
using System.Runtime.InteropServices;
2. DLLImport[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true, CallingConvention=CallingConvention.Winapi)]
3. Declare the function you want to use from the DLLprivate static extern short GetKeyState(int keyCode);
4. Declare a variable with the code for the NumLock Keyprivate const int VK_NUMLOCK = 0x90;
5. Declare a state function that will use the external function as source.MessageBox.Show("State: " + (IsKeyOn(VK_NUMLOCK) ? "YES" : "NO"));
Not sure if there is an easier way since this was posted in 2005 and may not be 2.0 framework, but i hope this helps,
Darren