問題描述
出于個人興趣,我正在研究我的擊鍵記錄器,昨天問了一個與此相關的問題;While 循環使用大量 CPU.
I am working on my keystroke logger for personal interest and asked a question related to this about yesterday; While loop using a lot of CPU.
該程序的問題在于它占用了太多的 CPU 使用率,人們建議讓輸入基于鍵事件.
The issue with the program was that it took too much CPU Usage, and people have suggested to make the inputs key-event based.
由于我是 Win32 API 的新手,所以我嘗試尋找參考資料和教程,它們將告訴我如何將鍵盤輸入創建為基于事件而不是基于輪詢.但問題是我找不到任何可靠的例子或參考資料,因為對于一個完整的新手來說很難理解.
Since I'm new to the Win32 API, I try to look for references and tutorials that will tell me how to create keyboard inputs as event-based, rather than poll based. But the problems is I could not found any solid examples or references, as it was quite difficult to understand for a complete newbie.
他們中的大多數人都提到基于事件的編程駐留在 GUI 應用程序中,但我希望這個擊鍵記錄器應用程序是一個控制臺應用程序.
Most of them mentioned that the event-based programming resided in GUI application, yet I want this keystroke logger application to be a console application.
我的兩個主要問題是:
- 我可以使用 Win32 API 編寫基于事件的控制臺按鍵記錄器嗎?如果沒有,我有哪些選擇?
和
- 有沒有人有任何參考網站可以幫助我了解如何基于事件捕獲擊鍵?
如果需要更多信息,我在 Windows XP 下使用代碼塊和 GCC 編譯器.
If additional information is needed, I am using Code Blocks under Windows XP with a GCC compiler.
推薦答案
按鍵記錄器應用程序使用諸如 Win32 鉤子.具體來說,您需要設置一個 WH_KEYBOARD
鉤子.
Key logger applications use mechanisms such as Win32 Hooks. Specifically you need to set a WH_KEYBOARD
hook.
有一些高級技術,比如創建自己的鍵盤驅動程序,但對于開始使用鉤子是一個不錯的選擇.
There are move advanced techniques, like creating your own keyboard driver but for a start hooks are a good choice.
為了了解鉤子過程的樣子,我發布了我個人實用程序中的一個片段.
To get an idea of how a hook procedure looks like, I post a fragment from my personal utility.
這篇關于C++ Win32 鍵盤事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!