curriculum_design/Data/HotKey.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/********************************************
* 注册快捷键 *
* Copy by MeiZhaoRui *
* 2014年04月10日 更新 *
*******************************************/
using System;
using System.Runtime.InteropServices;
namespace curriculum_design
{
public delegate void HotkeyEventHandler(int HotKeyID);
public class Hotkey : System.Windows.Forms.IMessageFilter
{
System.Collections.Hashtable keyIDs = new System.Collections.Hashtable();
IntPtr hWnd;
/// <summary>
/// Occurs when a hotkey has been pressed.
/// </summary>
public event HotkeyEventHandler OnHotkey;
public enum KeyFlags { None = 0x0, Alt = 0x1, Control = 0x2, Shift = 0x4, Win = 0x8 }
[DllImport("user32.dll")]
private static extern UInt32 RegisterHotKey(IntPtr hWnd, UInt32 id,UInt32 fsModifiers, UInt32 vk);
[DllImport("user32.dll")]
private static extern UInt32 UnregisterHotKey(IntPtr hWnd, UInt32 id);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern UInt32 GlobalAddAtom(String lpString);
[DllImport("kernel32.dll")]
private static extern UInt32 GlobalDeleteAtom(UInt32 nAtom);
/// <summary>
/// Constructor. Adds this instance to the MessageFilters so that this class can raise Hotkey events
/// </summary>
/// <param name="hWnd">A valid hWnd, i.e. form1.Handle</param>
public Hotkey(IntPtr hWnd)
{
this.hWnd = hWnd;
System.Windows.Forms.Application.AddMessageFilter(this);
}
/// <summary>
/// Register a system wide hotkey.
/// </summary>
/// <param name="hWnd">form1.Handle</param>
/// <param name="Key">Your hotkey</param>
/// <returns>ID integer for your hotkey. Use this to know which hotkey was pressed.</returns>
public int RegisterHotkey(System.Windows.Forms.Keys Key, KeyFlags keyflags)
{
UInt32 hotkeyid = GlobalAddAtom(System.Guid.NewGuid().ToString());
RegisterHotKey((IntPtr)hWnd, hotkeyid, (UInt32)keyflags, (UInt32)Key);
keyIDs.Add(hotkeyid, hotkeyid);
return (int)hotkeyid;
}
/// <summary>
/// Unregister hotkeys and delete atoms.
/// </summary>
public void UnRegisterHotkeys()
{
System.Windows.Forms.Application.RemoveMessageFilter(this);
foreach (UInt32 key in keyIDs.Values)
后面还有 25 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。