对啊,直接判断其VIRTUAL—KEY的值,不一样的

解决方案 »

  1.   

    Ctrl和Shift键分左右,而Alt键不分左右
      

  2.   

    其实不管在Windows9X还是在WindowsNT中的左键和右键在系统的底层的实现方法是一样的!可以用iState=GetKeyState(VK_SHIFT)如果按下了Shift,则iState值为负(即高位被置位)。如果CapsLock键打开,则从iState=GetKeyState(VK_CAPITAL)返回值低位被置位。此位与键盘上的小灯保持一致。通常,在使用GetKeyState时会带有虚拟键码VK_SHIFT、VK_CONTROL和VK_MENU(在说明ALT键时调用,所以上面有人说ALT不分左右是错误的)。使用GetKeyState时,您也可以用下面的标识符来确定按下的Shift、Ctrl或Alt键是左边还是右边的:VK_RSHIFT、VK_RSHIFT、VK_LCONTROL、VR_RCONTROL、VK_LMENU和VK_RMENU。好象这些标识符只能用于GetKeyState和GetAsyncKeyState。
      

  3.   

    对了,刚想起来还有VK_RWIN和VK_LWIN。
      

  4.   

    谢谢 hongyucn 的回答!但它不能实现,这个方法我以前已经试过了,不行!的确在MSDN中对于GetKeyState()的描述中说的于你说的一样,没有区分Windows9X和WinNT的差别〔我也是这样上当的〕;但翻到GetAsyncKeyState()的描述时你会发现那里明确的说明只能在WinNT中使用,对于Windows95其返回值为○;所以我看它们的底层实现未必完全相同,或者MS有意省略了什么,要知道在DOS下就可以区分的!
    你可以使用语句: iState=GetKeyState(VK_LCONTROL); /* 或VR_RCONTROL */
    然后你在看 iState 的值是不是○〔在Windows9X下〕!
      

  5.   

    至于 bensilver 的回答,你说Ctrl和Shift键分左右,那么这么区分呢?WinAPI中有这样的函数吗?如果有请指点一二!
      

  6.   

    的确还有 VK_RWIN和VK_LWIN,但在说明中已经明确注明它们是可以区分左右的,很简单;无论是在什么Windows系统中!
      

  7.   

    各位高手们,难道在Windows9X中就不能区分这些左右键呢? 
      

  8.   

    /*
     * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
     * Used only as parameters to GetAsyncKeyState() and GetKeyState().
     * No other API or message will distinguish left and right keys in this way.
     */
    #define VK_LSHIFT         0xA0
    #define VK_RSHIFT         0xA1
    #define VK_LCONTROL       0xA2
    #define VK_RCONTROL       0xA3
    #define VK_LMENU          0xA4
    #define VK_RMENU          0xA5
      

  9.   

    谢谢 Robert2001 的回答!但它仍不能实现,这个方法和hongyucn说的是一样的,的确在头文件WinUser.h中是这样定义的;但实际使用时会发现是不行的!对于Windows95其返回值始终为○;
    你可以使用语句: iState=GetKeyState(VK_LCONTROL); /* 或VR_RCONTROL */
    然后你再看 iState 的值是不是○〔在Windows9X下〕
    我害怕VC忽略这些定义,还专门直接在源文件中重新定义了一下,也不行!
    高手们,在下诚心请教各位有何高见!
      

  10.   

    to:No9(华龙) 
        大哥你问的 问题怎么这么变态
        我刚试了一下! 我这里也不行! 为什么呢! MSDN 写的是可以的啊!! 哎 晕菜!!
        你等等我在问 问别人!
      

  11.   

    拜托 Robert2001 你问的这么样了?
    有结果吗?
      

  12.   

    我手头的那本c用bios中断int16H都不能辨别ctrl和alt的左右呀??!!
    难道windows下有所不同??
      

  13.   

    残啊!!! 我跑到codeguru 上去问了半天 没人理我。
        MSDN 上讲的太笼统了。
        我觉得应该可以! 有些游戏 模拟器 就能区分 左右。    
      

  14.   

    气死我了!! 我又看了一眼 MSND! 上面写的很清楚!
     
    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. 
    看完了 我快要晕了。**号那里!!!!!!!!!!!!!!!!!!!
    我马上去做个  例子!! 你等等!!!
      

  15.   

    to:No9(华龙) 好了!! 你看这段代码就行了!! 调试通过
    case WM_KEYDOWN:
                
    switch(wParam)
    {
    case VK_CONTROL:
                        x= pow(2,24);
                     if(lParam & x)
    {
    MessageBox(NULL,"","",NULL);
    }
    break;
    }
    break;
     如果是右边的Ctrl 按下的话 就会弹出 MessageBox 左边的没有/  但是关于 GetKeyState(VK_RSHIFT);  还没有搞明白。
     
      

  16.   

    非常感谢 Robert2001 的回答以及您的代码!
    最近没有回复,让您和大家久等了,非常抱歉!
    首先我要告诉您,在您的帮助我已经完成了,就是这个方法,我在MSDN中看到了,但就是由于该死的MS和它的MSDN,让我上当了,它在两个不同的地方,说法不太一样,我一开始找对地方了,和您说的完成一样,但后来我又在里面找到了另一个说法:
    Value Description 
    0–15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key. 
    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 a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0. 
    -------------------------------------------------------
    25–28 Reserved. 
    29 Specifies the context code. The value is 1 if the alt key is down; otherwise, it is 0. 
    30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up. 
    31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released. 它这里没有提左右键的事情,而是关于功能键和小键盘的键,另外我的代码也有一些问题,所以就以为这种方法不正确呢!
    现在看到您的回答,我有重新翻阅了一下MSDN,整理整理代码,最后已经完成了!
    谢谢了!
    现在开始加分!
      

  17.   

    gameboy999 你所说的那本c用bios中断int16H都不能辨别ctrl和alt的左右键,不知道你的哪本书是不是太旧了!
    我在DOS很早就已经实现过了!
    你可以到下面的地址 http://chinahlsoft.myetang.com/Software/zbrj-d.htm 去下载“华龙编辑伴侣[DOS版] V5.1”软件,它就是我写的一个早期作品,就可以在DOS下分辨出Ctrl,Alt,Shift的左右键来!
    另外需要注意至少要下载一个数据文件悠!
      

  18.   

    我现在就是想将其在Windows下实现,没想到遇到现在的问题!