From: Boris Pauljev on 29 Apr 2010 01:50 I have an lParam which is "C02D0001". I need to extract certain information from this, but I have never done this before. Can anybody help and tell me how to get this information? From the documentation on MSDN I have the following hints: -------------- lParam Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. 0-15 Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. The repeat count is always one for a WM_KEYUP message. 16-23 Specifies the scan code. The value depends on the OEM. 24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 25-28 Reserved; do not use. 29 Specifies the context code. The value is always 0 for a WM_KEYUP message. 30 Specifies the previous key state. The value is always 1 for a WM_KEYUP message. 31 Specifies the transition state. The value is always 1 for a WM_KEYUP message. --------------- I guess all this information has been put into lParam, but I have no idea how to extract it... Thank you for the help.
From: Dee Earley on 29 Apr 2010 04:14 On 29/04/2010 06:50, Boris Pauljev wrote: > I have an lParam which is "C02D0001". > I need to extract certain information from this, but I have never done > this before. > Can anybody help and tell me how to get this information? > <SNIP> > I guess all this information has been put into lParam, but I have no > idea how to extract it... > Thank you for the help. Essentially, you need to use bitmasking and shifting. There are a few good demonstrations around if you google. > 0-15 16 bits, 2 bytes, already at the "low" end of the value. Mask (And) it with &H0000FFFF&, and no need to shift it. > 16-23 8 bits, 1 bytes, shifted left by 16 bits. Mask it with &H00FF0000 and then divide by &H10000& (16 0 bits after the 1) > 24 1 bit, shifted left by 24 bits. Here's where you need to pay attention :) Mask with &H01000000& (1 bit in position 24) and divide by &H100000& (24 0 bits) > 25-28 4 bits, shifted left by 25 bits. Mask with &H1E000000& (4 bits in position 25 to 28, 00011110-00000000-00000000-00000000) and divide by &H200000& (25 0 bits) These should give you enough info to get the other values. -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems (Replies direct to my email address will be ignored. Please reply to the group.)
From: Boris Pauljev on 29 Apr 2010 06:23 Thank you. I am having a serious problem... My code returns the wrong values for some reason, and I heavily under pressure.... I have the following: dim iKeyCode% iKeyCode = 1609 'originally it comes from "iKeyCode = VkKeyScanW(vKey)" Now I need to find out if this iKeyCode contains Shift, Ctrl, Alt To do this, I use the following: iShift = (iKeyCode And &HFF00&) \ &H100& iVKKey = iKeyCode And &HFF& bShift = iShift And vbShiftMask 'vbShiftMask = 1 bCtrl = iShift And vbCtrlMask 'vbCtrlMask = 2 bAltGr = iShift And vbAltMask 'vbAltMask = 4 But this returns really strange values (=the wrong ones) Can anybody tell me where I went wrong? This is what MSDN writes about it: If the function succeeds, the low-order byte of the return value contains the virtual-key code and the high-order byte contains the shift state, which can be a combination of the following flag bits. Return code Description Bit Meaning 1 Either SHIFT key is pressed. 2 Either CTRL key is pressed. 4 Either ALT key is pressed. 8 The Hankaku key is pressed Thank you so much again
From: Dee Earley on 29 Apr 2010 08:48 On 29/04/2010 11:23, Boris Pauljev wrote: > Thank you. > I am having a serious problem... > > My code returns the wrong values for some reason, and I heavily under > pressure.... > > I have the following: > > dim iKeyCode% > iKeyCode = 1609 'originally it comes from "iKeyCode = VkKeyScanW(vKey)" > > Now I need to find out if this iKeyCode contains > > Shift, Ctrl, Alt > > To do this, I use the following: > > iShift = (iKeyCode And &HFF00&) \ &H100& > iVKKey = iKeyCode And &HFF& > > bShift = iShift And vbShiftMask 'vbShiftMask = 1 > bCtrl = iShift And vbCtrlMask 'vbCtrlMask = 2 > bAltGr = iShift And vbAltMask 'vbAltMask = 4 > > But this returns really strange values (=the wrong ones) > > Can anybody tell me where I went wrong? How is it wrong? It looks like ctrl+alt+i to me using your code -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems (Replies direct to my email address will be ignored. Please reply to the group.)
From: Boris Pauljev on 29 Apr 2010 08:50
Thanks for your reply! You mean the results (what I make out of 1609 -> Shift+Alt+Ctrl) is correct??? This would mean that "only" the 1609 is wrong, and not my code regarding low byte order and high byte order and Shift and Alt and Ctrl. Could you please confirm that you think that I calculated it correctly? I am absolutely not sure. Thank you. |