>>Me again,
>>
>>I have been playing around with the WinApi's getKeyState and GetKeyboardState function to determine when the Shift, Ctrl, or Alt key are pressed when a routine occurs. But the results tend to be random. Does anyone have a solution that returns the state of these keys? FYI. the routine is occurring in a TImer. I am attempt to implement a more dynamic tooltip that would display the content based on the state of the shift state and the content the mouse happens to be over at the time.
>>
>>Any suggestion are welcome.
>
>Use
GetAsyncKeyState(). It returns a 32-bit value that can have the lower 16-bits parsed using BITAND(lnResult, 0x8000) to determine if the key is down or up (non-zero = down, zero = up).
>
>You can see
all of the virtual keys to test, including VK_SHIFT, VK_CONTROL, VK_MENU (alt), as well as VK_RSHIFT, VK_LSHIFT, etc.
>
>
#define key_lshift 0xa0
>#define key_rshift 0xa1
>#define key_lctrl 0xa2
>#define key_rctrl 0xa3
>#define key_lalt 0xa4
>#define key_ralt 0xa5
>
>DECLARE INTEGER GetAsyncKeyState IN WIN32API INTEGER nVKey
>
>LOCAL llLShiftDown, llRShiftDown, llLCtrlDown, llRCtrlDown, llLAltDown, llRAltDown
>llLShiftDown = isKeyDown(key_lshift)
>llRShiftDown = isKeyDown(key_rshift)
>llLCtrlDown = isKeyDown(key_lctrl)
>llRCtrlDown = isKeyDown(key_rctrl)
>llLAltDown = isKeyDown(key_lalt)
>llRAltDown = isKeyDown(key_ralt)
>
>* The same works for reading mouse buttons
>#define left_button 0x1
>#define right_button 0x2
>#define middle_button 0x4
>llLeftButtonDown = isKeyDown(left_button)
>llRightButtonDown = isKeyDown(right_button)
>llMiddleButtonDown = isKeyDown(middle_button)
>
>
>FUNCTION isKeyDown
>LPARAMETERS tnVKey
> RETURN (BITAND(GetAsyncKeyState(tnVKey), 0x8000) != 0)
>
>You can also BINDEVENTS(thisForm.HWnd, WM_KEYDOWN, "thisForm", "my_method") and intercept keystrokes which are made as they are made. This will be for any keystroke directed to that window. See
WM_KEYDOWN for the bits to examine there to retrieve the vKey and live state as it changes.
More good suggestions. Thanks. Fortunately my needs doesn't need to distinguish the Left/Right key or whether the key is Up or Down. Another tool for my toolbox. (can't have too many tools)
Greg Reichert