• 大小: 13.69MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-01
  • 语言: C#
  • 标签: c#  录屏  

资源简介

在网上找的基本用不了,后来自己结合别人的代码弄出来了,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个文件信息

评论

共有 条评论