久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='ijBT5'><style id='ijBT5'><dir id='ijBT5'><q id='ijBT5'></q></dir></style></legend>
    <i id='ijBT5'><tr id='ijBT5'><dt id='ijBT5'><q id='ijBT5'><span id='ijBT5'><b id='ijBT5'><form id='ijBT5'><ins id='ijBT5'></ins><ul id='ijBT5'></ul><sub id='ijBT5'></sub></form><legend id='ijBT5'></legend><bdo id='ijBT5'><pre id='ijBT5'><center id='ijBT5'></center></pre></bdo></b><th id='ijBT5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ijBT5'><tfoot id='ijBT5'></tfoot><dl id='ijBT5'><fieldset id='ijBT5'></fieldset></dl></div>
  • <tfoot id='ijBT5'></tfoot>

    <small id='ijBT5'></small><noframes id='ijBT5'>

        <bdo id='ijBT5'></bdo><ul id='ijBT5'></ul>

        了解低級(jí)鍵鼠鉤子(win32)

        Understanding the low-level mouse and keyboard hook (win32)(了解低級(jí)鍵鼠鉤子(win32))

          <tbody id='vfghc'></tbody>

        <small id='vfghc'></small><noframes id='vfghc'>

          <legend id='vfghc'><style id='vfghc'><dir id='vfghc'><q id='vfghc'></q></dir></style></legend>

              <tfoot id='vfghc'></tfoot>
                <i id='vfghc'><tr id='vfghc'><dt id='vfghc'><q id='vfghc'><span id='vfghc'><b id='vfghc'><form id='vfghc'><ins id='vfghc'></ins><ul id='vfghc'></ul><sub id='vfghc'></sub></form><legend id='vfghc'></legend><bdo id='vfghc'><pre id='vfghc'><center id='vfghc'></center></pre></bdo></b><th id='vfghc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vfghc'><tfoot id='vfghc'></tfoot><dl id='vfghc'><fieldset id='vfghc'></fieldset></dl></div>
                • <bdo id='vfghc'></bdo><ul id='vfghc'></ul>
                  本文介紹了了解低級(jí)鍵鼠鉤子(win32)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在嘗試捕獲全局鼠標(biāo)和鍵盤輸入.

                  I'm trying to capture global mouse and keyboard input.

                  LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
                    if (nCode >= 0) {
                      if (wParam == WM_RBUTTONDOWN) printf("right mouse down
                  ");
                      if (wParam == WM_RBUTTONUP) printf("right mouse up
                  ");
                    }
                    return CallNextHookEx(0, nCode, wParam, lParam);
                  }
                  
                  HHOOK mousehook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
                  while(true) {
                    MSG msg;
                    if (PeekMessage(&msg,0,0,0,PM_REMOVE)) {
                      printf("msg recvd
                  ");
                      TranslateMessage(&msg);
                      DispatchMessage(&msg);
                    }
                  #ifdef TEST
                    Sleep(50);
                  #endif
                  }
                  

                  所以這里一切正常,除非我 #define TEST 放入 Sleep,鼠標(biāo)變得非常遲鈍,如果我突然只允許鼠標(biāo)每秒更新 20 次.如果沒有睡眠,我將 CPU 固定在 100%.但這暫時(shí)沒問題(如果我使用 GetMessage 就會(huì)消失).

                  So everything works here, except if I #define TEST to put in the Sleep, the mouse becomes incredibly sluggish, as might be expected if I suddenly only allow the mouse to update 20 times a second. And without the sleep, I am pegging the CPU at 100%. But that's okay for now (that goes away if I use GetMessage).

                  現(xiàn)在據(jù)我所知,低級(jí)鉤子通過上下文切換到安裝它的進(jìn)程來工作,然后向進(jìn)程發(fā)送某種消息以讓它執(zhí)行鉤子回調(diào).不過,讓我有點(diǎn)困惑的是,為什么我的程序永遠(yuǎn)不會(huì)打印msg recvd",但每當(dāng)我單擊鼠標(biāo)右鍵時(shí),它就會(huì)打印鼠標(biāo)右鍵向下/向上".這使我得出結(jié)論,我的 MouseHookProcPeekMessage 調(diào)用期間被調(diào)用.它恰好是某種特殊的消息,PeekMessage 返回 0.但我仍然需要調(diào)用 PeekMessage 或一些等效的.

                  Now as I understand it, the low-level hooks work by context-switching to the process which installed it, and then sending the process some kind of message to let it execute the hook callback. What confuses me a little, though, is why my program will never print "msg recvd", but it prints "right mouse down/up" whenever i click the right mouse button. This leads me to conclude that my MouseHookProc is being invoked during the PeekMessage call. It just happens to be some kind of special message and PeekMessage returns 0. But I still need to call PeekMessage or some equivalent.

                  由于我的程序需要做很多事情,我顯然不能通過調(diào)用另一個(gè)需要 50 毫秒返回的函數(shù)來減輕我的消息泵循環(huán)(調(diào)用 PeekMessage 的那個(gè)).我如何多線程處理我的程序以保持鼠標(biāo)響應(yīng),同時(shí)做一些繁重的工作?在多線程的win32程序中,仍然只有一個(gè)消息隊(duì)列,對(duì)嗎?

                  Since my program needs to do a bunch of things, I clearly can't weigh down my message pumping loop (the one that calls PeekMessage) by calling another function that takes, say 50ms to return. How might I multithread my program to maintain mouse responsiveness while simultaneously doing a little heavy lifting? In a multithreaded win32 program, there is still just one message queue, right?

                  更新:在閱讀了 MS 的文檔后,我想我知道我應(yīng)該做什么是正確的.我應(yīng)該在我的應(yīng)用程序中生成一個(gè)線程,它調(diào)用 SetWindowsHookEx 來注冊(cè)鼠標(biāo)鉤子,然后坐在它自己的消息循環(huán)中,系統(tǒng)將負(fù)責(zé)將鼠標(biāo)更新發(fā)送到這個(gè)線程.它可以在 MouseHookProc 中自由地做任何它想做的事情,而我的應(yīng)用程序的其余部分將獨(dú)立運(yùn)行.

                  Update: After reading up on MS's documentation I think I know what the right thing for me to do is. I should just spawn a thread in my application which calls SetWindowsHookEx to register the mouse hook, and then sit around in its own message loop, and the system will take care of sending the mouse updates to this thread. It will be free to do whatever it wants within the MouseHookProc, and the rest of my application will run independently.

                  推薦答案

                  問題在于你的消息循環(huán),因?yàn)槟闶褂?PeekMessage(),它消耗了 100% 的 CPU 周期.即使您不輪詢消息,Windows 也知道如何使鉤子保持活動(dòng)狀態(tài),請(qǐng)使用 GetMessage() 來解決您的問題.使用 Sleep(1) 也可以解決您的問題,但在這里不是必需的.

                  The problem is your message loop, it burns 100% CPU cycles because you use PeekMessage(). Windows knows how to keep the hook alive even if you don't poll for messages, use GetMessage() to solve your problem. Using Sleep(1) will solve your problem too but is not necessary here.

                  為什么必須將 SetWindowsHookEx 與 Windows 消息隊(duì)列一起使用

                  這篇關(guān)于了解低級(jí)鍵鼠鉤子(win32)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當(dāng)沒有異常時(shí),C++ 異常會(huì)以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對(duì) const 的引用?)
                  When and how should I use exception handling?(我應(yīng)該何時(shí)以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對(duì)象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構(gòu)造函數(shù)的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區(qū)別)
                • <i id='W7LGI'><tr id='W7LGI'><dt id='W7LGI'><q id='W7LGI'><span id='W7LGI'><b id='W7LGI'><form id='W7LGI'><ins id='W7LGI'></ins><ul id='W7LGI'></ul><sub id='W7LGI'></sub></form><legend id='W7LGI'></legend><bdo id='W7LGI'><pre id='W7LGI'><center id='W7LGI'></center></pre></bdo></b><th id='W7LGI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='W7LGI'><tfoot id='W7LGI'></tfoot><dl id='W7LGI'><fieldset id='W7LGI'></fieldset></dl></div>

                        <tbody id='W7LGI'></tbody>

                      • <small id='W7LGI'></small><noframes id='W7LGI'>

                        1. <tfoot id='W7LGI'></tfoot><legend id='W7LGI'><style id='W7LGI'><dir id='W7LGI'><q id='W7LGI'></q></dir></style></legend>
                            <bdo id='W7LGI'></bdo><ul id='W7LGI'></ul>
                            主站蜘蛛池模板: 国产精品视频导航 | 国产成人免费 | 国产女人与拘做受免费视频 | www.亚洲视频 | 天天操网| 欧美视频三区 | 久久精品一区二区三区四区 | 成人免费一级视频 | 一区二区三区在线电影 | 日韩中文字幕 | 女生羞羞网站 | 亚洲精品乱码久久久久久久久久 | 亚洲精品成人网 | 中文字幕av色 | 国产在线一区二区三区 | 日韩福利片 | 一起操网站 | 精品美女久久久久久免费 | 国产一区二区三区免费观看视频 | 欧美精品一区二区在线观看 | 久久亚洲精品国产精品紫薇 | 亚洲一区在线日韩在线深爱 | 久久久久久看片 | 麻豆91精品91久久久 | 免费午夜剧场 | 亚洲欧美日本国产 | 99精品免费久久久久久久久日本 | 成人精品一区二区三区中文字幕 | 亚洲国产自产 | 久久国产精品网 | 国产在线观看免费 | 国产在线一区二区三区 | 香蕉一区| 久久艹av| www国产亚洲精品久久网站 | 久久久久一区 | 男女午夜免费视频 | 国产三级在线观看播放 | 成人欧美一区二区三区在线播放 | 日日摸夜夜爽人人添av | 亚洲日本视频 |