tags:

views:

299

answers:

2

hi, i am using an mfc ListCtrl, is there anyway to know if a selection change was caused by mouse/keyboard input rather than a programatic change? i am after the same behaviour as ON_LBN_SELCHANGE for a listbox. thanks

A: 

AFAIK there is no way to find out this information. You know if you are sending the message to the CListCtrl so you should set a flag if you do. If the LBN_SELCHANGE message is received and the flag has NOT been set then it must have come from a keyboard/mouse.

Goz
Thank you for your help Goz.
Jon
+1  A: 

You can use GetKeyState() to find out whether a key or mouse button was pressed. Do not use GetAsyncKeyState() because that API will tell you the current state of the keyboard/mouse buttons, which may have changed when you handle the LBN_SELCHANGE message. GetKeyState() however will tell you the state as it was when LBN_SELCHANGE was generated.

Stefan
Thanks very much Stefan.
Jon