mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 13:05:38 +02:00
TBD new feature: alt+w hotkey to invoke mouse gesture function
This commit is contained in:
parent
d8c882be3b
commit
8cad4d810b
4 changed files with 78 additions and 0 deletions
|
@ -572,6 +572,21 @@ namespace PersistentWindows.Common.WinApiBridge
|
|||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, uint wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
||||
|
||||
public enum KeyModifier
|
||||
{
|
||||
None = 0,
|
||||
Alt = 1,
|
||||
Control = 2,
|
||||
Shift = 4,
|
||||
WinKey = 8
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Kernel32
|
||||
|
|
61
Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs
Normal file
61
Ninjacrab.PersistentWindows.Solution/SystrayShell/HotKey.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using PersistentWindows.Common.WinApiBridge;
|
||||
|
||||
namespace PersistentWindows.SystrayShell
|
||||
{
|
||||
public class HotKeyForm : Form
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
Thread messageLoop = new Thread(() =>
|
||||
{
|
||||
Application.Run(new HotKeyForm());
|
||||
})
|
||||
{
|
||||
Name = "MessageLoopThread",
|
||||
IsBackground = true
|
||||
};
|
||||
|
||||
messageLoop.Start();
|
||||
}
|
||||
public HotKeyForm()
|
||||
{
|
||||
//InitializeComponent();
|
||||
|
||||
var r = User32.RegisterHotKey(this.Handle, 0, (int)User32.KeyModifier.Alt, 0x57); // Register Alt + W
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
if (m.Msg == 0x0312)
|
||||
{
|
||||
/* Note that the three lines below are not needed if you only want to register one hotkey.
|
||||
* The below lines are useful in case you want to register multiple keys, which you can use a switch with the id as argument, or if you want to know which key/modifier was pressed for some particular reason. */
|
||||
|
||||
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); // The key of the hotkey that was pressed.
|
||||
User32.KeyModifier modifier = (User32.KeyModifier)((int)m.LParam & 0xFFFF); // The modifier of the hotkey that was pressed.
|
||||
int id = m.WParam.ToInt32(); // The id of the hotkey that was pressed.
|
||||
|
||||
// do something
|
||||
//MessageBox.Show("Hotkey has been pressed!");
|
||||
}
|
||||
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
|
||||
protected override void SetVisibleCore(bool value)
|
||||
{
|
||||
// Ensure the window never becomes visible
|
||||
base.SetVisibleCore(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
User32.UnregisterHotKey(this.Handle, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -348,6 +348,7 @@ namespace PersistentWindows.SystrayShell
|
|||
StartSplashForm();
|
||||
}
|
||||
|
||||
//HotKeyForm.Start();
|
||||
Application.Run();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="HotKey.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue