In a C#.NET application (.dll automation) I have a form. I need to know if the F6-key is in the state of pressed down, when the form opens. I cannot detect it sooner, because I'm opening it from another application.
I've tried to make a keypresseventhandler, but it does'nt fire on F-keys, only the normal keys (a-z and others). And KeyDown only fires when the key is actually on its way down. I need to read the state of F6, because its pressed down in the other application (in which I've no control and cannot parse any parameters regarding keyboard) but it will still be in a state of pressed down when my own application opens.
The reason is that I'd like to position my form next to the mouse pointer (if it is open by mouseclick on button) or in center of screen (if it is open by keyboard shortcut to the same button).
Loading
JohnPosted Oct 12, 2006, 8:34 AM
You certainly got me on the right track and I've got it working. I wantet to open a calender from Navision (a financial program that does'nt have a calender) and center it on the screen if I pressed F6 inside Navision, and by the mouse if I used the mouse in stead of the keyboard. to open the calender.
Mike GoldPosted Oct 6, 2006, 4:50 PM
You can put a thread timer on the GetKeyState function and look to see the state of the Function key you are interested in:
[DllImport("user32.dll")]
static extern short GetKeyState(VirtualKeyStates nVirtKey);
VK_F1 = 0x70,
VK_F2 = 0x71,
VK_F3 = 0x72,
VK_F4 = 0x73,
VK_F5 = 0x74,
VK_F6 = 0x75,
VK_F7 = 0x76,
VK_F8 = 0x77,
VK_F9 = 0x78,
VK_F10 = 0x79,
VK_F11 = 0x7A,
VK_F12 = 0x7B
Best Mike G.