C# 钩子-找不到类型或命名空间钩子类型
我正在尝试学习使用C#的Win32 API中的钩子。我实际上要做的是,当存在诸如鼠标移动或按键之类的低级用户活动时,如何调用命令。我目前正在阅读这篇文章: 但是,当我从示例中输入以下代码时:C# 钩子-找不到类型或命名空间钩子类型,c#,api,winapi,hook,C#,Api,Winapi,Hook,我正在尝试学习使用C#的Win32 API中的钩子。我实际上要做的是,当存在诸如鼠标移动或按键之类的低级用户活动时,如何调用命令。我目前正在阅读这篇文章: 但是,当我从示例中输入以下代码时: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.ComponentModel;
using System.Reflection;
class Win32Hooks
{
[DllImport("user32.dll")]
public static extern IntPtr SetWindowsHookEx(HookType code,
CbtHook.CbtProc func,
IntPtr hInstance,
int threadID);
[DllImport("user32.dll")]
public static extern int UnhookWindowsHookEx(IntPtr hhook);
static void Main()
{
}
}
但是,我收到一个错误,即找不到类型或命名空间“HookType”。你知道怎么解决这个问题吗?如果有人能为初学者推荐一篇关于带C#的Win32 API挂钩的文章,那也太好了。我一直在努力搜索,但我找到的最清楚的是上面粘贴的这一个。您还没有定义
HookType
类型(消息很容易解释,不是吗?)
钩子类型在您引用的文章中定义
public enum HookType : int
{
WH_JOURNALRECORD = 0,
WH_JOURNALPLAYBACK = 1,
WH_KEYBOARD = 2,
WH_GETMESSAGE = 3,
WH_CALLWNDPROC = 4,
WH_CBT = 5,
WH_SYSMSGFILTER = 6,
WH_MOUSE = 7,
WH_HARDWARE = 8,
WH_DEBUG = 9,
WH_SHELL = 10,
WH_FOREGROUNDIDLE = 11,
WH_CALLWNDPROCRET = 12,
WH_KEYBOARD_LL = 13,
WH_MOUSE_LL = 14
}
请看这里,我建议初学者不要学习Win32 API,不管有没有C#。对不起,我以为这篇文章是一步一步地结构的,我错了。约翰·桑德斯:我不是一个完全的C#初学者,我懂几种语言。我的意思是,我是Windows API函数和类的初学者。对不起,我没有看到它,以为文章中的内容是另一种结构。谢谢