我用UINT MapVirtualKey()把一个字母“A”的虚拟键值转换为扫描码:UINT i = MapVirtualKey(0x41, 0);这时i的值是多少??大写A和小写a的虚拟键值都是0x41,这个函数怎么判断并把它转换为相应的扫描码?当用这个函数把虚拟键值转换为ASC2码时也是一样,它怎么区分大小写?我现在想把一个ASC2码转换为扫描码,能不能请各位高手写一下转化过程!!谢谢!!

解决方案 »

  1.   

    扫描码是指键盘上的键按下产生的码,那么键盘上只有一个a键,当然A和a的扫描码一样,之所以有大小写是因为Caps Lock或者Shift在起作用,所以扫描码和ASCII是两回事
      

  2.   

    直接给你来一段MSDN吧
    WM_KEYDOWN
    The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the alt key is not pressed. WM_KEYDOWN 
    nVirtKey = (int) wParam;    // virtual-key code 
    lKeyData = lParam;          // key data 
     
    Parameters
    nVirtKey 
    Value of wParam. Specifies the virtual-key code of the nonsystem key. 
    lKeyData 
    Value of 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. Value Description 
    0–15       Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated 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      Specifies the scan code. The value depends on the original equipment manufacturer (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_KEYDOWN message. 
    30             Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up. 
    31              Specifies the transition state. The value is always 0 for a WM_KEYDOWN message. 
      

  3.   

    扫描码和硬件键盘的内部电路有关,由于都使用标准的键盘,所以大家就认为和硬件无关了。键盘驱动程序负责把扫描码转化成键盘的扩展ASCII码,键盘上单个字符的扩展ASCII的高字节为0,可以产生WM_CHAR消息,多个键的组合键,例如ALT+A,就会有一些额外的扫描信息表示ALT键也按下了,扩展ASCII的高字节不为0。在实际使用时并不需要关心和设置这个扫描码。