
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Based on WindowsHook by topstarai. Added injected flag detection to both mouse events and keyboard events. This is useful if for example you want to preform continuous mouse clicks of the same type of the currently held down mouse button. Supports .Net 4.8,.Net 6+, WinForm, WPF etc.
This library allows you to tap keyboard and mouse, to detect and record their activity even when an application is inactive and runs in background.
nuget install WindowsHookEx
private IKeyboardMouseEvents globalHook = Hook.GlobalEvents();
private bool IsLeftMouseDown;
private bool IsRightMouseDown;
private void Subscribe()
{
globalHook.MouseDownExt += GlobalHook_MouseDownExt;
globalHook.MouseUpExt += GlobalHook_MouseUpExt;
}
private void UnSubscribe()
{
globalHook.MouseDownExt -= GlobalHook_MouseDownExt;
globalHook.MouseUpExt -= GlobalHook_MouseUpExt;
globalHook.Dispose();
}
private void GlobalHook_MouseDownExt(object? sender, MouseEventExtArgs e)
{
switch (e.Button)
{
case MouseButtons.Left: if (!e.IsInjected) IsLeftMouseDown = true; break;
case MouseButtons.Right: if (!e.IsInjected) IsRightMouseDown = true; break;
}
if(IsLeftMouseDown)
{
_ = FastClick();
}
}
private void GlobalHook_MouseUpExt(object? sender, MouseEventExtArgs e)
{
switch (e.Button)
{
case MouseButtons.Left: if (!e.IsInjected) IsLeftMouseDown = false; break;
case MouseButtons.Right: if (!e.IsInjected) IsRightMouseDown = false; break;
}
}
private async Task FastClick()
{
await Task.Run(() =>
{
while(IsLeftMouseDown)
{
//Send left mouse click code here
Thread.Sleep(100);
}
});
}
private IKeyboardMouseEvents m_GlobalHook;
public void Subscribe()
{
// Note: for the application hook, use the Hook.AppEvents() instead
m_GlobalHook = Hook.GlobalEvents();
m_GlobalHook.MouseDownExt += GlobalHookMouseDownExt;
m_GlobalHook.KeyPress += GlobalHookKeyPress;
}
private void GlobalHookKeyPress(object sender, KeyPressEventArgs e)
{
Console.WriteLine("KeyPress: \t{0}", e.KeyChar);
}
private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
{
Console.WriteLine("MouseDown: \t{0}; \t System Timestamp: \t{1}", e.Button, e.Timestamp);
// uncommenting the following line will suppress the middle mouse button click
// if (e.Buttons == MouseButtons.Middle) { e.Handled = true; }
}
public void Unsubscribe()
{
m_GlobalHook.MouseDownExt -= GlobalHookMouseDownExt;
m_GlobalHook.KeyPress -= GlobalHookKeyPress;
//It is recommened to dispose it
m_GlobalHook.Dispose();
}
(also have a look at the Demo app included with the source)
This library attaches to windows global hooks, tracks keyboard and mouse clicks and movement,please note this don't support common .Net events with KeyEventArgs and MouseEventArgs. this is the difference with WindowsHook project. But you can still easily retrieve any information you need:
Additionally, there are MouseEventExtArgs
and KeyEventExtArgs
which provide further options:
The MIT license see: LICENSE.txt
FAQs
Fork of WindowsHook with added injected flag detection.
We found that windowshookex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.