简体   繁体   English

从 WM_CHAR 消息中获取扫描码

[英]Get scan code from WM_CHAR message

How can I convert a character of any language that I catch via WM_CHAR in WndProc to a keyboard scan code?如何将通过WndProc中的WM_CHAR捕获的任何语言的字符转换为键盘扫描代码? Like if the button pressed is x it would return 0x2d and etc.就像按下的按钮是x它会返回 0x2d 等等。

The scan code is in bits 16-23 of the lParam parameter according to the WM_CHAR documentation, so just shift and mask:根据WM_CHAR文档,扫描代码位于 lParam 参数的第 16-23 位,因此只需移位和屏蔽:

int scanCode = (lParam >> 16) & 0xff;

If you've got a character you can call OemKeyScan , which puts the scan code in the low byte:如果你有一个字符,你可以调用OemKeyScan ,它将扫描码放在低字节中:

char c='X';
int scanCode=OemKeyScan(c) & 0x0ff;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM