mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 21:15:38 +02:00
Alt+Q invokes mouse gesture window
This commit is contained in:
parent
f62281c6c8
commit
7c45e4ae2a
4 changed files with 114 additions and 9 deletions
|
@ -247,6 +247,10 @@ namespace PersistentWindows.Common.WinApiBridge
|
|||
[DllImport("user32.dll")]
|
||||
public static extern bool PtInRect([In] ref RECT lprc, POINT pt);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetFocus(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsWindowVisible(IntPtr hWnd);
|
||||
|
|
|
@ -8,12 +8,13 @@ namespace PersistentWindows.SystrayShell
|
|||
{
|
||||
public class HotKeyForm : Form
|
||||
{
|
||||
static HotKeyWindow hkwin = new HotKeyWindow();
|
||||
static HotKeyWindow hkwin = null;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
Thread messageLoop = new Thread(() =>
|
||||
{
|
||||
hkwin = new HotKeyWindow();
|
||||
Application.Run(new HotKeyForm());
|
||||
})
|
||||
{
|
||||
|
@ -34,6 +35,7 @@ namespace PersistentWindows.SystrayShell
|
|||
{
|
||||
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. */
|
||||
|
||||
|
@ -41,11 +43,7 @@ namespace PersistentWindows.SystrayShell
|
|||
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.
|
||||
|
||||
if (!User32.IsWindowVisible(hkwin.Handle))
|
||||
hkwin.Show();
|
||||
else
|
||||
User32.ShowWindow(hkwin.Handle, (int)ShowWindowCommands.Hide);
|
||||
|
||||
hkwin.HotKeyPressed();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,16 +34,16 @@ namespace PersistentWindows.SystrayShell
|
|||
// HotKeyWindow
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
this.ClientSize = new System.Drawing.Size(537, 353);
|
||||
this.BackColor = System.Drawing.SystemColors.MenuHighlight;
|
||||
this.ClientSize = new System.Drawing.Size(400, 300);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||
this.KeyPreview = true;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "HotKeyWindow";
|
||||
this.Opacity = 0.2D;
|
||||
this.ShowIcon = false;
|
||||
this.ShowInTaskbar = false;
|
||||
this.Text = "HotKeyWindow";
|
||||
//this.TopMost = true;
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Timers;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
|
@ -8,13 +9,115 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using PersistentWindows.Common.WinApiBridge;
|
||||
|
||||
namespace PersistentWindows.SystrayShell
|
||||
{
|
||||
public partial class HotKeyWindow : Form
|
||||
{
|
||||
private System.Timers.Timer aliveTimer;
|
||||
private System.Timers.Timer clickDelayTimer;
|
||||
public HotKeyWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
KeyDown += new KeyEventHandler(FormKeyDown);
|
||||
MouseDown += new MouseEventHandler(FormMouseDown);
|
||||
|
||||
aliveTimer = new System.Timers.Timer(2000);
|
||||
aliveTimer.Elapsed += AliveTimerCallBack;
|
||||
aliveTimer.SynchronizingObject = this;
|
||||
aliveTimer.AutoReset = false;
|
||||
aliveTimer.Enabled = false;
|
||||
|
||||
clickDelayTimer = new System.Timers.Timer(1000);
|
||||
clickDelayTimer.Elapsed += ClickTimerCallBack;
|
||||
clickDelayTimer.SynchronizingObject = this;
|
||||
clickDelayTimer.AutoReset = false;
|
||||
clickDelayTimer.Enabled = false;
|
||||
}
|
||||
|
||||
private void FormMouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
else if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void FormKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Q)
|
||||
{
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void HotKeyPressed()
|
||||
{
|
||||
if (InvokeRequired)
|
||||
BeginInvoke((Action) delegate ()
|
||||
{
|
||||
HotKeyPressed();
|
||||
});
|
||||
else
|
||||
{
|
||||
if (!User32.IsWindowVisible(Handle))
|
||||
{
|
||||
POINT cursor;
|
||||
User32.GetCursorPos(out cursor);
|
||||
Left = cursor.X - 200;
|
||||
Top = cursor.Y - 150;
|
||||
Show();
|
||||
User32.SetForegroundWindow(Handle);
|
||||
StartAliveTimer();
|
||||
}
|
||||
else
|
||||
User32.ShowWindow(Handle, (int)ShowWindowCommands.Hide);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void StartAliveTimer(int milliseconds = 2000)
|
||||
{
|
||||
aliveTimer.Interval = milliseconds;
|
||||
aliveTimer.AutoReset = false;
|
||||
aliveTimer.Enabled = true;
|
||||
}
|
||||
|
||||
public void StartClickDelayTimer(int milliseconds)
|
||||
{
|
||||
clickDelayTimer.Interval = milliseconds;
|
||||
clickDelayTimer.AutoReset = false;
|
||||
clickDelayTimer.Enabled = true;
|
||||
}
|
||||
|
||||
private void ClickTimerCallBack(Object source, ElapsedEventArgs e)
|
||||
{
|
||||
}
|
||||
private void AliveTimerCallBack(Object source, ElapsedEventArgs e)
|
||||
{
|
||||
// TODO: restart timer if alt key pressed
|
||||
|
||||
/*
|
||||
if (this.InvokeRequired)
|
||||
BeginInvoke((Action) delegate ()
|
||||
{
|
||||
AliveTimerCallBack(source, e);
|
||||
});
|
||||
else
|
||||
*/
|
||||
{
|
||||
if (User32.IsWindowVisible(Handle))
|
||||
User32.ShowWindow(Handle, (int)ShowWindowCommands.Hide);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue