資源簡介
在網(wǎng)上找的基本用不了,后來自己結合別人的代碼弄出來了,vs2013 + win7 sp1測試可以使用
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Diagnostics;
using?System.Runtime.InteropServices;
using?System.Windows.Forms;
namespace?ScreenRecoder
{
????public?class?KeyboardHook
????{
????????int?hHook;
????????Win32Api.HookProc?KeyboardHookDelegate;
????????public?event?KeyEventHandler?onkeydownEvent;
????????public?event?KeyEventHandler?onkeyupEvent;
????????public?event?KeyPressEventHandler?onkeypressEvent;
????????public?KeyboardHook()?{?}
????????public?void?SetHook()
????????{
????????????KeyboardHookDelegate?=?new?Win32Api.HookProc(KeyboardHookProc);
????????????Process?cProcess?=?Process.GetCurrentProcess();
????????????ProcessModule?cModule?=?cProcess.MainModule;
????????????var?mh?=?Win32Api.GetModuleHandle(cModule.ModuleName);
????????????hHook?=?Win32Api.SetWindowsHookEx(Win32Api.WH_KEYBOARD_LL?KeyboardHookDelegate?mh?0);
????????}
????????public?void?UnHook()
????????{
????????????Win32Api.UnhookWindowsHookEx(hHook);
????????}
????????private?List?preKeysList?=?new?List();//存放被按下的控制鍵,用來生成具體的鍵
????????private?int?KeyboardHookProc(int?nCode?Int32?wParam?IntPtr?lParam)
????????{
????????????//如果該消息被丟棄(nCode<0)或者沒有事件綁定處理程序則不會觸發(fā)事件
????????????if?((nCode?>=?0)?&&?(onkeydownEvent?!=?null?||?onkeyupEvent?!=?null?||?onkeypressEvent?!=?null))
????????????{
????????????????Win32Api.KeyboardHookStruct?KeyDataFromHook?=?(Win32Api.KeyboardHookStruct)Marshal.PtrToStructure(lParam?typeof(Win32Api.KeyboardHookStruct));
????????????????Keys?keyData?=?(Keys)KeyDataFromHook.vkCode;
????????????????//按下控制鍵
????????????????if?((onkeydownEvent?!=?null?||?onkeypressEvent?!=?null)?&&?(wParam?==?Win32Api.WM_KEYDOWN?||?wParam?==?Win32Api.WM_SYSKEYDOWN))
????????????????{
????????????????????if?(IsCtrlAltShiftKeys(keyData)?&&?preKeysList.IndexOf(keyData)?==?-1)
????????????????????{
????????????????????????preKeysList.Add(keyData);
????????????????????}
????????????????}
????????????????//WM_KEYDOWN和WM_SYSKEYDOWN消息,將會引發(fā)onkeydownEvent事件
????????????????if?(onkeydownEvent?!=?null?&&?(wParam?==?Win32Api.WM_KEYDOWN?||?wParam?==?Win32Api.WM_SYSKEYDOWN))
????????????????{
????????????????????KeyEventArgs?e?=?new?KeyEventArgs(GetDownKeys(keyData));
????????????????????onkeydownEvent(this?e);
????????????????}
????????????????//WM_KEYDOWN消息將引發(fā)onkeypressEvent?
????????????????if?(onkeypressEvent?!=?null?&&?wParam?==?Win32Api.WM_KEYDOWN)
????????????????{
????????????????????byte[]?keyState?=?new?byte[256];
????????????????????Win32Api.GetKeyboardState(keyState);
????????????????????byte[]?inBuffer?=?new?byte[2];
????????????????????if?(Win32Api.ToAscii(KeyDataFromHook.vkCode?KeyDataFromHook.scanCode?keyState?inBuffer?KeyDataFromHook.flags)?==?1)
????????????????????{
????????????????????????KeyPressEventArgs?e?=?new?KeyPressEventArgs((char)inBuffer[0]);
????????????????????????onkeypressEvent(this?e);
????????????????????}
????????????????}
????????????????//松開控制鍵
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????29184??2015-07-20?11:32??ScreenRecoder\.vs\ScreenRecoder\v14\.suo
?????文件??????98304??2016-02-25?09:32??ScreenRecoder\ScreenRecoder\bin\Debug\Interop.WMEncoderLib.dll
?????文件????2677382??2016-02-24?16:58??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160224-165607.wmv
?????文件?????349606??2016-02-24?17:08??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160224-170746.wmv
?????文件????2253720??2016-02-24?17:10??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160224-171022.wmv
?????文件?????493618??2016-02-25?09:45??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160225-093814.wmv
?????文件?????349594??2016-03-09?11:44??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-114421.wmv
?????文件????1381714??2016-03-09?14:28??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-142817.wmv
?????文件?????333876??2016-03-09?14:34??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-143420.wmv
?????文件??????85606??2016-03-09?14:36??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-143615.wmv
?????文件?????701624??2016-03-09?14:46??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-144631.wmv
?????文件?????325612??2016-03-09?14:47??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-144712.wmv
?????文件?????317642??2016-03-09?14:48??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-144747.wmv
?????文件?????301600??2016-03-09?14:48??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-144822.wmv
?????文件?????669630??2016-03-09?14:49??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-144900.wmv
?????文件???????5388??2016-03-09?14:58??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-145814.wmv
?????文件???????5388??2016-03-09?14:58??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-145825.wmv
?????文件?????717648??2016-03-09?15:04??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-150424.wmv
?????文件?????973630??2016-03-09?15:06??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-150556.wmv
?????文件????1013624??2016-03-09?15:10??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-151012.wmv
?????文件???????5388??2016-03-09?15:11??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-151059.wmv
?????文件???????5388??2016-03-09?15:12??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-151208.wmv
?????文件?????405636??2016-03-09?15:20??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-151947.wmv
?????文件?????789624??2016-03-09?15:25??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-152453.wmv
?????文件?????805618??2016-03-09?16:07??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-160707.wmv
?????文件?????629630??2016-03-09?16:19??ScreenRecoder\ScreenRecoder\bin\Debug\Screen\20160309-161839.wmv
?????文件???????5826??2015-07-20?09:45??ScreenRecoder\ScreenRecoder\bin\Debug\screen.prx
?????文件?????175104??2016-03-09?16:24??ScreenRecoder\ScreenRecoder\bin\Debug\ScreenRecoder.exe
?????文件??????46592??2016-03-09?16:24??ScreenRecoder\ScreenRecoder\bin\Debug\ScreenRecoder.pdb
?????文件??????22704??2016-03-09?16:24??ScreenRecoder\ScreenRecoder\bin\Debug\ScreenRecoder.vshost.exe
............此處省略72個文件信息
評論
共有 條評論