我的代码:
SHORT ks=GetKeyState(VK_LSHIFT);
不管我有没有按左SHILFT,结果是ks一直为0.
有没有人碰到过?

解决方案 »

  1.   

    Windows 95/98: Windows 95 does not support the left- and right-distinguishing constants. If you call GetAsyncKeyState with these constants, the return value is zero.BOOL GetKeyboardState(
      PBYTE lpKeyState   // pointer to array to receive status data
    );
    可以支持区分左右
    VK_LSHIFT VK_RSHIFT 
    VK_LCONTROL VK_RCONTROL 
    VK_LMENU VK_RMENU 
     
      

  2.   

    checkyvc6(checkyvc6) :
    谢谢!
    你试过吗?这个问题是我在编写一个输入法出来的,我用应用程序传给输入法的键盘状态数组进行检测也不能区分大小写,我以为键盘状态数组应该和GetKeyboardState得到的数据相同。
    我现在还没有试,成功了就给分。
      

  3.   

    可是我在论坛搜索时其它人也碰到了同样的问题。
    而且最后的结论是在98下用GetKeyState无法区分左右键。
    我用GetKeyboardState(BYTE *buf)后,测试buf[VK_LSHIFT]及buf[VK_RSHIFT]结果都是0,但测试buf[VK_SHIFT]时,当我按下left shift时得到0x81,右键时得到0x80,我也不知道这样做安不安全。
      

  4.   

    checkyvc6(checkyvc6) :
    不行啊!还有什么办法?
      

  5.   

    msdn上邊沒有說GetKeyState的限制,只是說,如果要得到所有的虛擬鍵信息,則用GetKeyboardState,所以,用checkyvc6的方法應該可以。
    msdn如下:An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT    VK_RSHIFT 
    VK_LCONTROL    VK_RCONTROL 
    VK_LMENU    VK_RMENU 
    These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. 
      

  6.   

    兄弟们,MSDN并不是圣经啊!
    什么事件,只有实践才是最有说服力的。
    因为我是做输入法,所以我问了一个做输入法的同行,他说他是通过加载键盘勾子实现的。
    真不知道是不是只有这一个解决办法?
      

  7.   

    就目前来说,比较可靠的方法就是区分扫描码。0x2a=left,0x36=right