win32程式測試鍵盤鉤子

2021-06-09 18:29:29 字數 1507 閱讀 8310

// test_hook.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include #include #include #include #include // some global variables

hinstance g_instance; // handler of current instance

hhook g_hook; // handler of hook

bool sethook();

bool unsethook();

// the hook function (will be called by other processes)

static lresult callback keyboardproc(int ncode, wparam wparam, lparam lparam);

////odprintf -- debug function

void __cdecl odprintf(const char* fmt, ...)

lresult callback keyboardproc(int ncode, wparam wparam, lparam lparam)

//判斷函式呼叫時指定虛擬鍵的狀態

//bool bctrlkey = ::getasynckeystate(vk_control) & 0x8000;

bool bctrlkey = ::getasynckeystate(vk_control)>>((sizeof(short) * 8) - 1);

if ((pkh->vkcode == vk_escape && bctrlkey) || // ctrl+esc 開始選單

(pkh->vkcode == vk_tab && pkh->flags & llkhf_altdown) || // alt+tab 螢幕切換選單

(pkh->vkcode == vk_escape && pkh->flags & llkhf_altdown) || // alt+esc 螢幕切換

(pkh->vkcode == vk_lwin || pkh->vkcode==vk_rwin) // 左右windows鍵) }

// call next hook in chain

return ::callnexthookex(g_hook, ncode, wparam, lparam);

}bool sethook()

return true; // hook has been created correctly

}bool unsethook()

return true; // hook has been removed

}int _tmain(int argc, _tchar* argv)

//clean:

unsethook();

return 0;

}

win32 鍵盤 滑鼠事件

onkeyuup 事件的語法為 void object1 onkeyup uint nchar,uint nrepcnt,uint nflags onkeydown 事件的語法為 void object1 onkeydown uint nchar,uint nrepcnt,uint nflags 這...

C開發win32程式

1,先建立乙個空的win32工程,再建立乙個c 原始檔到此工程 2,編輯原始檔 include 標頭檔案宣告 int winapi winmain hinstance hinstance,hinstance hprevinstance,pstr szcmdline,int icmdshow 主函式為...

win 32 程式開發流程

windows 程式分為 程式 和 ui user inte ce 資源 兩大部份,兩部份最後以rc 編譯器集成為乙個完整的exe 檔案 圖1 1 所謂ui 資源是指功能選單 對話方塊 外貌 程式圖示 游標形狀等等東西。這些ui 資源的實際內容 二進位制 系借助各 種工具產生,並以各種副檔名存在,如...