资源简介
在网上找的基本用不了,后来自己结合别人的代码弄出来了,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)或者没有事件绑定处理程序则不会触发事件
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消息,将会引发onkeydownEvent事件
if (onkeydownEvent != null && (wParam == Win32Api.WM_KEYDOWN || wParam == Win32Api.WM_SYSKEYDOWN))
{
KeyEventArgs e = new KeyEventArgs(GetDownKeys(keyData));
onkeydownEvent(this e);
}
//WM_KEYDOWN消息将引发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个文件信息
相关资源
- C# 源代码员工考勤管理系统
- C#语言程序设计(第二版!)全部资源
- 学生学籍管理系统(C#+Access)
- c#操作摄像头(带着usb摄像头、mjpeg
- 管理系统c#+sql完整项目版
- Visual C#.NET数据库开发经典案例解析(
- C#与halcon窗体控件交互
- C#课程设计案例精编
- C#通讯录实现
- C#二次开发之海康威视摄像机登录、预
- Asp.net mvc编写的人员管理系统(入门级
- 员工考勤管理系统源码
- Visual C#.NET串口通信及测控应用典型(
- 深入理解c#(第3版) 中文版带书签
- c#实现USB摄像头录像抓拍功能
- C# 票务管理系统包含完整的源码、设
- Unity 5实战:使用C#和Unity开发多平台游
- c# 微信接口,包括小程序,企业微信
- wpf聊天小程序
- Essential C# 7.0 6th Edition.pdf
- Effective C#(covers C# 6.0).pdf
- FluentFTP已编译
- MapEditor地图的使用C#版
- C#桌面应用程序开发教程
- webkit.net 0.5版c#和winform嵌入chrome核心浏
- C#使用ModbusTcp协议与西门子1200PLC通讯
- C#制作KTV点歌系统,包括前台的点歌和
- 深入理解C#第三版英文版
- sqlite-netFx40-setup-bundle-x86-2010-1.0.97.0.
- ARCGIS ENGINE+C#入门经典__赵银军
评论
共有 条评论