[英]What is the behaviour of lParam when WM_KEYDOWN message recived?
I started learning winapi using c++ language.我开始使用 c++ 语言学习 winapi。 I am trying to understand the
lParam
on WM_KEYDOWN message.我试图了解 WM_KEYDOWN 消息上的
lParam
。
From the Microsoft documentation:从微软文档:
0-15 : The repeat count for the current message.
0-15 :当前消息的重复计数。 The value is the number of times the keystroke is autorepeated as a result of the user holding down the key.
该值是由于用户按住键而自动重复击键的次数。 If the keystroke is held long enough, multiple messages are sent.
如果击键时间足够长,则会发送多条消息。 However, the repeat count is not cumulative.
但是,重复计数不是累积的。
16-23 : The scan code.
16-23 :扫码。 The value depends on the OEM.
该值取决于 OEM。
24 : Indicates 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.
24 :指示该键是否为扩展键,例如出现在增强的 101 或 102 键键盘上的右手 ALT 和 CTRL 键。 The value is 1 if it is an extended key;
如果是扩展键,则值为 1; otherwise, it is 0.
否则为 0。
25-28 : Reserved;
25-28 :保留; do not use.
不使用。
29 :The context code.
29 :上下文代码。 The value is always 0 for a WM_KEYDOWN message.
对于 WM_KEYDOWN 消息,该值始终为 0。
30 : The previous key state.
30 :前一个键 state。 The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
如果在发送消息之前密钥已关闭,则该值为 1,如果密钥已启动,则该值为 0。
31 : The transition state.
31 :过渡 state。 The value is always 0 for a WM_KEYDOWN message.
对于 WM_KEYDOWN 消息,该值始终为 0。
I am handling this message by this way:我正在通过这种方式处理此消息:
case WM_KEYDOWN:
cout << ((lParam & 0b11111111111111110000000000000000) >> 16) << ", ";
cout << ((lParam & 0b00000000000000001111111100000000) >> 8) << ", ";
cout << ((lParam & 0b00000000000000000000000010000000) >> 7) << ", ";
cout << ((lParam & 0b00000000000000000000000000000100) >> 2) << ", ";
cout << ((lParam & 0b00000000000000000000000000000010) >> 1) << ", ";
cout << ((lParam & 0b00000000000000000000000000000001) >> 0) << endl;
And if I press "A" button on my keyboard I get ouput: 30, 0, 0, 0, 0, 1
如果我按键盘上的“A”按钮,我会得到输出:
30, 0, 0, 0, 0, 1
If I hold "A" button I get muliple outputs:如果我按住“A”按钮,我会得到多个输出:
16414, 0, 0, 0, 0, 1
16414, 0, 0, 0, 0, 1
16414, 0, 0, 0, 0, 1
If I press other letter button, I get same result but with other first number.如果我按其他字母按钮,我会得到相同的结果,但有其他第一个数字。 (For example, for "B" button I get 48 as simple press, 49200 as holding)
(例如,对于“B”按钮,我得到 48 作为简单的按下,49200 作为保持)
How can I understand it?我怎么理解?
I didn't test this, but your bit ordering appears to be reversed.我没有对此进行测试,但是您的位顺序似乎是相反的。 According to MS Documentation , bits 0-15 are the LOW bits.
根据MS Documentation ,位 0-15 是低位。
case WM_KEYDOWN:
cout << ((lParam & 0b00000000000000001111111111111111) >> 0) << ", ";
cout << ((lParam & 0b00000000111111110000000000000000) >> 16) << ", ";
cout << ((lParam & 0b00000001000000000000000000000000) >> 24) << ", ";
cout << ((lParam & 0b00100000000000000000000000000000) >> 29) << ", ";
cout << ((lParam & 0b01000000000000000000000000000000) >> 30) << ", ";
cout << ((lParam & 0b10000000000000000000000000000000) >> 31) << ", ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.