首先,虽然您可能会通过加入现有项目为世界做出更多贡献,但我要说:我的乐趣在哪里?因此,如果您这样做是为了学习和享受乐趣,那么您应该全力以赴。
全局键:
是的,可以通过挂钩到 Windows 消息循环来实现。它需要 user32.dll 和 kernel32.dll 的 dll 导入。我以前做过这样的事情:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace DevBoard.App
{
internal class InterceptKeys
{
#region Delegates
public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
#endregion
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
public static IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc,GetModuleHandle(curModule.ModuleName), 0);
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook,
LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
}
}
搜索
如果您想做一些高级索引搜索,可以查看Lucene.Net
编码愉快! :)