关于ToAscii function的疑问。一定给分!!!

fanzai 2003-08-20 03:22:33
我没有搞懂ToAscii的第二个参数uScanCode有什么用。我在调试程序时好像将uScanCode的值添错了,但是结果却没有受影响,甚至我把它添成 0 运行都很正常!!!
Why???

ToAscii 在MSDN里面的解释如下:
The ToAscii function translates the specified virtual-key code and keyboard state to the corresponding character or characters. The function translates the code using the input language and physical keyboard layout identified by the keyboard layout handle.

To specify a handle to the keyboard layout to use to translate the specified code, use the ToAsciiEx function.

int ToAscii(
UINT uVirtKey, // virtual-key code
UINT uScanCode, // scan code
CONST PBYTE lpKeyState, // key-state array
LPWORD lpChar, // buffer for translated key
UINT uFlags // active-menu option
);
Parameters
uVirtKey
[in] Specifies the virtual-key code to be translated.
uScanCode
[in] Specifies the hardware scan code of the key to be translated. The high-order bit of this value is set if the key is up (not pressed).
lpKeyState
[in] Pointer to a 256-byte array that contains the current keyboard state. Each element (byte) in the array contains the state of one key. If the high-order bit of a byte is set, the key is down (pressed).
The low bit, if set, indicates that the key is toggled on. In this function, only the toggle bit of the CAPS LOCK key is relevant. The toggle state of the NUM LOCK and SCROLL LOCK keys is ignored.

lpChar
[out] Pointer to the buffer that receives the translated character or characters.
uFlags
[in] Specifies whether a menu is active. This parameter must be 1 if a menu is active, or 0 otherwise.
...全文
130 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanzai 2003-09-02
  • 打赏
  • 举报
回复
抱歉,好久没来。
马上结贴!!
xiaohedou 2003-08-21
  • 打赏
  • 举报
回复
奇怪!你晚上上的怎么是15:22:33?UINT uScanCode, // scan code应该是键盘的扫描码。因为键盘是一个单片机的程序记得以前是8031芯片。我估计有两个表:一个用在单片机里,一个用在PC的编程里。
scancode[键盘总数] = {1,2,3,4,5,....};
对应于虚拟码:
virtualTab[键盘总数] = { 'a','b',.... };
bluestar 2003-08-21
  • 打赏
  • 举报
回复
是键值的高字节啊
通常在钩子里这样用
vKey=LOBYTE(lparam);
nScan=HIBYTE(lparam);
按我理解如果不是Ctrl+X、Alt+X这类的组合键,这个就没有用,设0就行
如果是CTRL,the nScan is 1900554.ALT is 367000,Del is 5439488
farfh 2003-08-21
  • 打赏
  • 举报
回复
你设置为0xff00试试??我没试过,呵呵
balas 2003-08-21
  • 打赏
  • 举报
回复
Although keybd_event passes an OEM-dependent hardware scan code to the system, applications should not use the scan code. The system converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to applications
上面是函数keybd_event 的说明。
在windows 下,我以前在应用时一般设这项为0就行了。
fanzai 2003-08-21
  • 打赏
  • 举报
回复
怎么没人理我?
fanzai 2003-08-20
  • 打赏
  • 举报
回复
为什么没人回答?
大家都晚上才来CSDN吗?

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧