MouseLock
=========
A tiny, standalone tray tool with two independent features:
1. Monitor Lock - confines your mouse cursor to one monitor, using
Windows' own ClipCursor() function directly.
2. Windows Key - blocks the Windows key so it stops opening the Start
Menu / triggering Win+ shortcuts.
Both talk to Windows directly -- no dependency on DisplayFusion, Synergy,
or anything else being installed or running.
RUNNING IT
----------
Just double-click mouselock.exe. There's no installer and nothing is added
to Windows startup -- it only runs while you keep it open, and both
features start OFF every time, even if you had them on last time.
You'll see a small tray icon (a monitor with a padlock on its screen) --
you may need to click the little "^" arrow near the clock to see it, and
can drag it out onto the visible tray if you want it always shown.
- Grey, open padlock = nothing currently engaged
- Orange, closed padlock = at least one feature (Monitor Lock and/or
Windows Key) is currently engaged
Since there are now two independent things it can be doing, check the
tray tooltip (hover over the icon) or the right-click menu for the exact
state of each -- the icon alone just tells you "something is on."
TWO FEATURES, EACH WITH ITS OWN ON/OFF SWITCH
-----------------------------------------------
Right-click the tray icon to open the menu:
"Lock to Monitor" >
Monitor 1 / Monitor 2 / Monitor 3 / ... - pick which monitor to
lock the cursor to.
Disabled - turns Monitor Lock off
as a feature. If it was
currently locked, picking
this releases it right away.
"Windows Key" >
Enabled / Disabled - turns Windows-key blocking on or off as a
feature. Choosing Disabled immediately
un-blocks the key if it was currently blocked.
These are independent master switches, not the same as "currently locked."
Enabling a feature just makes it available to toggle -- it doesn't engage
it by itself. So you can set this up as: only Monitor Lock (leave Windows
Key on Disabled), only Windows Key (leave Monitor Lock's "Disabled" option
selected), or both together -- whatever you want.
THE HOTKEY AND TRAY CLICK: ONE ACTION, ACTS ON WHATEVER'S ENABLED
---------------------------------------------------------------------
- Left-click the tray icon, or press your configured hotkey (there's only
ever one) -- both do exactly the same thing: toggle every feature that
is currently set to Enabled.
- Both enabled -> one click/press engages (or releases) both together.
- Only one enabled -> that click/press only affects that one.
- Both disabled -> nothing happens (you'll get a tray notification
telling you so, in case you forgot).
- There is no hotkey by default -- it's blank until you set one from the
menu ("Set Hotkey...": press the combination you want, e.g. Ctrl+Alt+L;
it checks the combo isn't already used by another running app before
accepting it; Esc cancels). "Change Hotkey..." / "Clear Hotkey" show up
once one is set, so you can reassign or remove it any time -- if it ever
conflicts with a game or another app's shortcut, just set a different one.
Your monitor choice, which features are Enabled, and your hotkey are all
remembered in mouselock.ini (created next to the .exe the first time you
change any of them). The ENGAGED state is never remembered -- every time
you start MouseLock, both features start released/unblocked, exactly like
before.
MONITOR SELECTION DEFAULT
--------------------------
On first run, Monitor Lock defaults to Enabled, pointed at whichever
monitor sits in the middle, horizontally, in a 3-monitor layout. With any
other monitor count, it defaults to whatever Windows reports as your
primary monitor. Windows Key defaults to Disabled (it's the newer, opt-in
feature). You can always change either from the right-click menu.
If you unplug the monitor you had locked, MouseLock notices, releases the
lock, and shows a tray notification -- it won't leave your cursor stuck
confined to a rectangle that no longer exists.
A NOTE ON HOW ClipCursor WORKS (please read this one)
-------------------------------------------------------
ClipCursor is the real Windows API for confining the cursor -- there's no
deeper or more "official" way to do this outside of a kernel driver. That
said, it has one inherent limitation that applies no matter who writes the
tool: any app can call ClipCursor() itself, and some fullscreen games and
other utilities do, which can momentarily override the lock while that
app has focus. MouseLock fights back by re-applying its own clip several
times a second whenever it's locked, so in practice it should hold up
against most things, but it's not a guarantee against every possible app.
This is a property of the Windows API itself, not a corner MouseLock cut.
Similarly, if Windows locks your session, signs you out, or shuts down
while MouseLock is locked, Windows itself clears the cursor clip when the
desktop session ends -- you don't need to do anything about that.
A NOTE ON HOW THE WINDOWS-KEY BLOCK WORKS
--------------------------------------------
This uses a low-level keyboard hook (the same general technique most
"disable the Windows key" utilities use) to intercept and swallow the Win
key before it reaches the Start Menu or any Win+ shortcut. It's genuinely
effective for that -- but a few very specific combinations (Ctrl+Alt+Del
is the classic example, and Win+L on some systems) are handled by Windows
at a lower level than any ordinary app is allowed to touch, for security
reasons, and can't be blocked by this or any similar tool running as a
normal user-mode program. Everyday use of the Win key itself and most
Win+letter shortcuts, though, are blocked as expected.
The hook is only installed while Windows Key is both Enabled AND currently
engaged -- if you leave the feature Disabled (the default), MouseLock
isn't touching your keyboard input at all.
IF YOU WANT TO MODIFY THE CODE
-------------------------------
mouselock.c is the entire program (single file, heavily commented) and
mouselock.rc/app.manifest/*.ico are its resources. build.bat rebuilds it
using a MinGW-w64 toolchain (see the comments at the top of build.bat for
how to get one via MSYS2, which is free). You don't need any of this just
to run the tool -- it's here in case you ever want to tweak it yourself.
FILES IN THIS FOLDER
---------------------
mouselock.exe - the program. This is the only file you need to run it.
mouselock.c - full source code
mouselock.rc - resource script (wires up the icons + manifest)
mouselock_res.h - shared resource ID constants
app.manifest - Windows manifest (DPI-awareness, themed dialog)
locked.ico / unlocked.ico - the two tray icon states (monitor + padlock)
build.bat - rebuild script (needs MinGW-w64 on PATH)
mouselock.ini - created automatically once you change a setting
(not present until then; safe to delete to reset)
LICENSE
-------
MIT License -- see LICENSE. Use it, modify it, share it, whatever's useful.