Hi all, I'm using .NET 2003 and trying to use the status bar to display
current key states, as so very many apps do - like num lock, caps lock,
etc. I'm using the following code (in c sharp but equally applicable
to vb, c++ etc.):
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]
private static extern short GetKeyState(int keyCode);
private const int VK_CAPITAL = 0x14;
private const int VK_INSERT = 0x2D;
private const int VK_OVERWRITE = 0x2D;
private const int VK_NUMLOCK = 0x90;
private const int VK_SCROLL = 0x91;
public bool IsKeyOn(int nKey)
{
return (GetKeyState(nKey) & 1) > 0;
}
....
string strBob = (IsKeyOn(VK_INSERT) ? "INS" : "OVR");
This works great for NUM lock & CAPS lock (haven't bothered with SCROLL
lock) but doesn't appear to work properly with INSERT/OVERWRITE -
sometimes it's right, sometimes not - switching apps affects it, etc.
Also, while it's right just after building on my PC, install the
packaged app onto an NT4 machine and it seems consitently wrong.
I've tried just about everything I can think of with this and it's
making my head hurt as the (limited) documentation appears to tell me
it should work. Any ideas very gratefully received.
Or if I've posted it into the completely wrong group, it'd be helpful
to know that too.
Thanks for your time,
Toot.