Click to See Complete Forum and Search --> : Detecting SHIFT+key and CTRL+key, how ?
Ali Imran
June 15th, 2005, 08:17 PM
In WM_KEYDOWN event I can get ascii value of key pressed as
LOWORD(wParam)
It returns the smae value even if shift key is also pressed
Can anyone please tell me how to detect if shift key, ctrl key, or both are pressed with some other normal key ?
regards
kirants
June 15th, 2005, 08:25 PM
GetAsyncKeyState
Ali Imran
June 15th, 2005, 08:45 PM
Hello
what does 'GetAsyncKeyState' mean ?
is it a function ? if so then, how many parameters does it accept etc etc ?
I am sory but this does not make sense to me.
kirants
June 15th, 2005, 08:49 PM
Well, how did you know WM_KEYDOWN message had a LOWORD(wParam) of key pressed ?
Please lookup MSDN. When it comes to programming for Win32, MSDN is the one stop reference place.
Smasher/Devourer
June 15th, 2005, 09:16 PM
In WM_KEYDOWN event I can get ascii value of key pressed as
LOWORD(wParam)
The value of wParam is not an ASCII code, it's a virtual-key code. The values happen to coincide for letters and numbers, but may not otherwise. For example, the 0 key on the main part of the keyboard and the 0 key on the number pad have different virtual-key codes, even though they produce the same character when pressed (and therefore the same ASCII code). For a complete list of virtual-key codes, please see this page (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/virtualkeycodes.asp) on MSDN.
As was said, GetAsyncKeyState() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/getasynckeystate.asp) is a useful function for determining the status of a key. It accepts a virtual-key code as its sole parameter, and returns a short whose high bit indicates whether the key is held or not. So for example, to check the status of the up arrow key, you might use:
if (GetAsyncKeyState(VK_UP) & 0x8000)
{
// up arrow key is depressed; do something
}
+J_o_S_H
June 15th, 2005, 10:29 PM
you could do that.....but thats too easy :D
RegisterHotKey(hwnd,1,MOD_SHIFT,0x48); //VK_H
RegisterHotKey(hwnd,2,MOD_CONTROL,0x53); //VK_S
//HOTKEY FOR SHIFT+H
//HOTKEY FOR CONTROL+S
case WM_HOTKEY:
switch(wParam)
{
case 1:
//your code here
break;
case 2:
//your code here
break;
}
case WM_DESTROY:
{
UnregisterHotKey(hwnd,1);
UnregisterHotKey(hwnd,2);
}
Just giving u options :)
Ali Imran
June 15th, 2005, 10:42 PM
Great josh
Your example is much better to incorporate with my exsiting code.
Thank you Smasher/Devourer and kirants too.
regards
slapout
June 16th, 2005, 09:11 AM
Please lookup MSDN. When it comes to programming for Win32, MSDN is the one stop reference place.
I've found that an easy way to look up API functions is to type the name into Google. Usually the first one is a link to the MSDN page for that function.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.