• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            面對(duì)現(xiàn)實(shí),超越自己
            逆水行舟,不進(jìn)則退
            posts - 269,comments - 32,trackbacks - 0

            MSDN中解釋:
            Determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.

            Syntax

            SHORT WINAPI GetAsyncKeyState(   _In_  int vKey );

            Parameters

            vKey [in]

            Type: int

            The virtual-key code. For more information, see Virtual Key Codes.

            You can use left- and right-distinguishing constants to specify certain keys. See the Remarks section for further information.

            Return value

            Type: SHORT

            If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks.

            The return value is zero for the following cases:

            • The current desktop is not the active desktop
            • The foreground thread belongs to another process and the desktop does not allow the hook or the journal record. 


              以下轉(zhuǎn)自:http://bingtears.iteye.com/blog/663149

              0x8000 & GetKeyState(VK_SHIFT); 這句是判斷是否有按下shift鍵 

              為什么GetAsyncKeyState()& 

              首先說明,有好多程序或書上是0x8000f,這個(gè)f不是十六進(jìn)制的f而是代表浮點(diǎn)數(shù)。其實(shí)& 8000才是本質(zhì)。小魚我整理后自己寫了點(diǎn)東西,總結(jié)一下 


              首先介紹一下幾個(gè)概念: 
              按位與運(yùn)算符"&":是雙目運(yùn)算符,其功能是參與運(yùn)算的兩數(shù)各對(duì)應(yīng)的二進(jìn)位相與。只有對(duì)應(yīng)的兩個(gè)二進(jìn)位均為1時(shí),結(jié)果位才為1 ,否則為0。參與運(yùn)算的數(shù)以補(bǔ)碼方式出現(xiàn)。例如:0x11 & 0x12(即0001 0001 & 0001 0010)的結(jié)果是0x10(0001 0000);(關(guān)于vs取反參考附) 
              虛鍵:指的是非字母可以明確表示的鍵.(例如ESC BS TAB NumLock 等,虛鍵列表見附); 
              物理鍵狀態(tài):在操作系統(tǒng)的控制面板中設(shè)置鼠標(biāo)左右鍵的映射(實(shí)際的鼠標(biāo)左鍵可以映射成右鍵點(diǎn)擊事件),或者通過程序也可以這樣設(shè)置,這樣就產(chǎn)生了(實(shí)際的)物理鍵狀態(tài); 
              邏輯鍵狀態(tài):使用 GetKeyState,GetKeyboardState,等函數(shù)得到的邏輯鍵狀態(tài),模擬按下按鍵; 
              GetAsyncKeyState函數(shù)功能:讀取的是物理鍵狀態(tài),也是就是不管你怎么鼠標(biāo)鍵盤映射,它只讀取實(shí)際的按鍵狀態(tài)。MSDN上給出了例子很恰當(dāng)For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button.也就是說如果你重新設(shè)置了映射,GetAsyncKeyState還是只讀取物理狀態(tài); 
              GetAsyncKeyState的返回值:表示兩個(gè)內(nèi)容,一個(gè)是最高位bit的值,代表這個(gè)鍵是否被按下,按下為1,抬起為0;一個(gè)是最低位bit的值,在windowsCE下要忽略(參考自MSDNIf the most significant bit is set, the key is down. The least significant bit is not valid in Windows CE, and should be ignored.) 
              Asynchronous:英文意思是異步的 

              實(shí)際當(dāng)中GetAsyncKeyState的返回值是什么呢?小魚我寫了個(gè)程序來獲取返回值: 
              #include <Windows.h> 
              #include <stdio.h> 

              void main() 

              while(1) 

              short a = ::GetAsyncKeyState(VK_LSHIFT) 
              printf( "0x%x",a); 
              sleep(10); 


              當(dāng)然,用MessageBox可以這樣寫: 
              if(short a = ::GetAsyncKeyState(VK_LSHIFT)) 

              char buffer[30]; 
              sprintf(buffer, "0x%x",a); 
              MessageBox(0, buffer, "a的值", MB_OK); 


              GetAsyncKeyState按鍵不按或抬起后不按的返回值0x0        即0000 0000 0000 0000 0000 0000 0000 0000 
              GetAsyncKeyState按鍵被按下后的返回值    返回0xffff8001 即1111 1111 1111 1111 1000 0000 0000 0001   (這里并不是返回4字節(jié),而是%x打印出32位,前十六位補(bǔ)f) 
              0x8000 即0000 0000 0000 0000 1000 0000 0000 0000 
              GetAsyncKeyState(VK_LSHIFT) & 0x8000    返回0x1          即0000 0000 0000 0000 1000 0000 0000 0000 

              那么為什么GetAsyncKeyState要 ‘與’上 0x8000這個(gè)常數(shù)呢? 
              答案是:獲取按鍵狀態(tài),屏蔽掉其他的可能狀態(tài),按照MSDN上說低位should ignore。 
              網(wǎng)上有人這樣寫,意思很明確: 
              #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) 
              #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) 

              程序應(yīng)該是: 
              if(GetAsyncKeyState(VK_LSHIFT)&&0x8000) 
              對(duì)于虛鍵而言下面這樣寫邏輯是不對(duì)的,雖然結(jié)果一樣: 
              if(GetAsyncKeyState(VK_LSHIFT)) 

              所以讓鍵盤的"上下左右"出發(fā)事件可以這樣寫: 
              if( ::GetAsyncKeyState(VK_LEFT) & 0x8000 ) 
              code... 
              if( ::GetAsyncKeyState(VK_RIGHT)& 0x8000 ) 
              code... 
              if( ::GetAsyncKeyState(VK_UP) & 0x8000 ) 
              code... 
              if( ::GetAsyncKeyState(VK_DOWN) & 0x8000 ) 
              code... 

              關(guān)于GetAsyncKeyState與GetKeyState區(qū)別: 
              GetAsyncKeyState上面已經(jīng)講差不多了,關(guān)于GetAsyncKeyState與GetKeyState二者最大區(qū)別:GetAsyncKeyState在按鍵不按的情況下為0,而GetKeyState在按鍵不按的情況下開始為0,當(dāng)一次‘按下抬起’后變?yōu)?,依次循環(huán)。 

              SHORT GetKeyState(int nVirtKey   // virtual-key code); 
              作用:返回鍵的狀態(tài),按下、釋放或鎖定(down、up or toggled) 
              參數(shù):虛擬鍵代碼(VK_)。如果是字母a-z、A-Z 或數(shù)字0-9, 則為其對(duì)應(yīng)的ASCII碼(比如字母O的ASCII碼為十六進(jìn)制的0x4F) 
              返回值:返回碼的高位顯示當(dāng)前是否有鍵被按下,低位(0位)則顯示NumLock、CapsLock、ScrollLock的狀態(tài)(ON或OFF,為ON時(shí)鍵盤指示燈亮)。即高位為1,返回值小于0,說明有鍵按下;最低位為1表示處于鎖定(ON)狀態(tài)(參考MSDN:If the high-order bit is 1, the key is down; otherwise, it is up. 
              If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled. ) 
              注:此函數(shù)不應(yīng)該在鍵盤消息處理程序以外使用,因?yàn)樗祷氐男畔⒅挥性阪I盤消息從消息隊(duì)列中被檢索到之后才有效。若確實(shí)需要,請(qǐng)使用GetAsyncKeyState 

              ---------------------------------------- 
              網(wǎng)上還找到了一些資料: 

              關(guān)于和其他的幾個(gè)函數(shù)的區(qū)別: 
              SHORT GetKeyState(int nVirtKey); 
              SHORT GetAsyncKeyState(int vKey); 
              BOOL GetKeyboardState(PBYTE lpKeyState); 

              三個(gè)取key status的函數(shù)的最大區(qū)別是: 
              第一個(gè):是從windows消息隊(duì)列中取得鍵盤消息,返回key status. 
              第二個(gè):是直接偵測(cè)鍵盤的硬件中斷,返回key status. 
              第三個(gè):是當(dāng)從windows消息隊(duì)列中移除鍵盤消息時(shí),才返回key status. 

              keybd_event函數(shù),是模擬鍵盤擊鍵,一次完整的擊鍵模擬事件,是"按下"和"彈起"兩個(gè)消息,所以 keybd_event(VK_F12,0,0,0);keybd_event(VK_F12,0,KEYEVENTF_KEYUP,0); 完成了一次完整的點(diǎn)擊 F12 的事件。 

              GetAsyncKeyState()函數(shù),是直接偵測(cè)鍵盤的硬件中斷。(有些人說,是一種“實(shí)時(shí)性”的偵測(cè),這種說法,感覺不對(duì),比如你調(diào)用 Sleep(),就算是中斷一年的時(shí)間,只要在這期間程序還在運(yùn)行,它都可以把那個(gè)鍵的狀態(tài)偵測(cè)出來)。自上一次調(diào)用GetAsyncKeyState()函數(shù)以來(在某些循環(huán)中,N次調(diào)用GetAsyncKeyState(),它每次檢查的,都是自上次調(diào)用之后,鍵的狀態(tài)),若鍵已被按過,則返回1,否則,返回0;有些資料顯示:倘若輸入焦點(diǎn)從屬于與調(diào)用函數(shù)的輸入線程不同的另一個(gè)線程,則返回零(例如,在另一個(gè)程序擁有輸入焦點(diǎn)時(shí),應(yīng)該返回零)。實(shí)驗(yàn)證明,這種說法并不完全,函數(shù)實(shí)際是在大部份范圍內(nèi)工作的,只有少數(shù)是另外)。 
            posted on 2012-11-23 15:55 王海光 閱讀(1919) 評(píng)論(0)  編輯 收藏 引用 所屬分類: MFC
            久久综合狠狠色综合伊人| 一级做a爰片久久毛片人呢| 久久精品国产99国产精品澳门| 综合久久给合久久狠狠狠97色| 99久久综合狠狠综合久久止| 久久水蜜桃亚洲av无码精品麻豆| 亚洲午夜久久久影院伊人| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 久久久综合香蕉尹人综合网| 亚洲综合精品香蕉久久网97| 91精品免费久久久久久久久| 成人精品一区二区久久| 国产精品VIDEOSSEX久久发布| 狠狠久久综合| 亚洲日韩欧美一区久久久久我| 中文精品99久久国产 | 91精品国产91久久久久久蜜臀| av无码久久久久久不卡网站| 久久精品国产99国产电影网 | 国产L精品国产亚洲区久久| 日本久久久久久中文字幕| 久久国产视屏| 99久久国产精品免费一区二区 | 日韩人妻无码精品久久免费一| 久久精品日日躁夜夜躁欧美| 久久无码国产专区精品| 色婷婷综合久久久久中文 | 一个色综合久久| 久久精品国产亚洲av水果派| 国产免费久久精品丫丫| 亚洲国产精品无码久久久久久曰| 亚洲精品无码久久久久去q | 99久久人妻无码精品系列蜜桃| 青青草国产精品久久| 久久婷婷国产剧情内射白浆| 国产精品岛国久久久久| 婷婷久久综合九色综合绿巨人| 国产亚洲精品美女久久久| 久久综合视频网| Xx性欧美肥妇精品久久久久久| 无码人妻久久一区二区三区免费丨|