Winodws 下監控熱鍵觸發

2021-10-02 22:41:17 字數 3737 閱讀 9364

1.使用定時器定時的從鍵盤掃瞄,看是否觸發

例項**如下:

#ifndef _hotkey_h_

#define _hotkey_h_

#include

#include

#include

#include

#define mod_none 0x0000

typedef

unsigned

int hotkey_id;

typedef dword pfunc;

typedef

struct taghotkey_info

hotkey_info,

*photkey_info;

void

handletheevents()

;void

superdelay

(int nelapse,

int nunit =0)

;void hotkeytest()

;void hotkeytest2()

; hotkey_id hotkeymonitor

(pfunc pfncallbackfunc, byte keycode, byte funckeystatus = mod_none, byte anotherkeycode =

0, uint uelapse = user_timer_minimum, bool bdirecttrigger = false)

;void callback hotkeymonthread

(hwnd hwnd, uint umsg, uint_ptr idevent, dword dwtime)

;bool hotkeyunmonitor

(hotkey_id hotkeyid =0)

;#endif

#include

"stdafx.h"

#include

"hotkey.h"

std::vector hotkeylist;

void

handletheevents()

}void

superdelay

(int nelapse,

int nunit)

closehandle

(htimer)

;return;}

switch

(nunit)

for(

int i =

0; i < nunit; i++

)closehandle

(htimer)

;return;}

} void hotkeytest()

void hotkeytest2()

/* .function name: hotkeymonitor,監視乙個熱鍵, 當熱鍵被觸發時啟用響應事件.(成功返回熱鍵標識, 失敗返回0).注:必須真實的按鍵才會觸發熱鍵

.parameter pfncallbackfunc, 子程式指標, , 響應事件(熱鍵標識, 其它...), 事件引數數目不限!如果再次監視熱鍵將響應事件!

.parameter keycode, 位元組型, , 觸發事件的基本鍵

.parameter funckeystatus, 位元組型, 可空, 1 alt 2 ctrl 4 shift 8 win 若要兩個或以上的狀態鍵, 則把它們的值相加,可以使用相應的巨集mod_alt,mod_control,mod_shift,mod_win來位或運算

.parameter anotherkeycode, 位元組型, 可空, 如果你需要註冊由兩個普通鍵組合的熱鍵, 可設定乙個其它鍵**.

.parameter uelapse, 無符號整數型, 可空, 預設為10, 監視熱鍵的週期時間(建議5 - 200之間)

.parameter bdirecttrigger, 邏輯型, 可空, 預設為假:建立新的執行緒事件 真 : 直接呼叫事件等待返回 */

hotkey_id hotkeymonitor

(pfunc pfncallbackfunc, byte keycode, byte funckeystatus, byte anotherkeycode, uint uelapse, bool bdirecttrigger)}

temphotkeyinfo.pfncallbackfunc = pfncallbackfunc;

temphotkeyinfo.keycode = keycode;

temphotkeyinfo.funckey = funckeystatus;

temphotkeyinfo.anotherkeycode = anotherkeycode;

temphotkeyinfo.bdirecttrigger = bdirecttrigger;

temphotkeyinfo.hotkeyid =

1000001

+ hotkeylist.

size()

; hotkeylist.

push_back

(temphotkeyinfo);if

(1000001

== temphotkeyinfo.hotkeyid)

settimer

(null

,666

, uelapse,

(timerproc)

&hotkeymonthread)

;return temphotkeyinfo.hotkeyid;

}//監視熱鍵執行緒

void callback hotkeymonthread

(hwnd hwnd, uint umsg, uint_ptr idevent, dword dwtime)

for(std::vector

::iterator it = hotkeylist.

begin()

; it != hotkeylist.

end(

); it++)}

else

if(bytemp <0)

if(it-

>bykeystatus >

0&& it-

>bykeystatus !=88)

pfntempevent = it-

>pfncallbackfunc;

utempid = it-

>hotkeyid;

if(it-

>bdirecttrigger)

callwindowproca

((wndproc)pfntempevent,

(hwnd)utempid,0,

0,0)

;else

closehandle

(createthread

(null,0

,(lpthread_start_routine)pfntempevent,

(lpvoid)utempid,0,

null))

;}}}

}}/*

.function name: hotkeyunmonitor, 邏輯型 撤消由監視熱鍵註冊的乙個或全部熱鍵(成功返回真,失敗返回假)

.parameter hotkeyid, hotkey_id型, 可空, 欲撤消的熱鍵標識,如果留空則撤消全部熱鍵 */

bool hotkeyunmonitor

(hotkey_id hotkeyid)

}return(0

== hotkeyid)

;}

winodws下gtk開發環境的安裝(msys2)

官網 清華大學映象 中國科學技術大學映象 按照官方指導安裝msys2後按如下方法修改映象源 修改映象源 修改三個檔案 1 c msys32 etc pacman.d mirrorlist.mingw32 清華大學 server 中國科學技術大學 server server server server...

JS監控enter觸發事件

回車事件 body bind keyup function ascii表 ascii值 控制字元 ascii值 控制字元 ascii值 控制字元 ascii值 控制字元 0nut 32 space 64 96 1soh33!65a97a 2stx34 66b98b 3etx35 67c99c 4eo...

SQL Server Audit監控觸發器狀態

原文 sql server audit監控觸發器狀態 本文所涉及的內容 contents 背景 contexts 實現 sql codes 注意事項 attention 疑問 questions 參考文獻 references dml觸發器一般會運用在業務系統的邏輯處理上,在你對資料庫使用者許可權控...