spiegel-keyman/windows/src/engine/keyman
Marc Durdin 711541be60 fix(windows): reinstall low level keyboard hook if it gets removed
This change improves the stability of Keyman for Windows by monitoring
the health of the low level keyboard hook. If keyman.exe is unresponsive
at any time, Windows can silently uninstall its low level keyboard hook,
which results in (at least) two problems:

* Keyman's hotkeys stop working
* A modifier key can become stuck, if it was pressed around the time
  Keyman became unresponsive.

The most common scenario in which Keyman can become unresponsive is high
system load, e.g. rendering graphics, videoconference calls, compiling
software.

Restarting Keyman always resolved both of these two issues in the past,
but with this patch, I hope that this will no longer be necessary.

A related 'fakefreeze' project is included for simulating a keyman.exe
hang by posting a `wm_keyman_control:KMC_WATCHDOG_FAKEFREEZE` message to
it, which keyman.exe responds to by `Sleep()`ing for 5 seconds. While
keyman.exe is freezing, any keystroke will cause the low level hook to
be uninstalled by Windows.

Logging has been updated; look for "LowLevelHookWatchDog" in the log for
related events.

One final small change in keyman32.cpp, as I refactored the
WH_KEYBOARD_LL hook installation/uninstallation, was to always clear out
hook variables when uninstalling a hook, because if the hook fails to
uninstall, there's really nothing we can do about it anyway, and we
probably shouldn't be trying again.

Fixes: #8064
2025-11-17 16:30:43 +01:00
..
langswitch fix(windows): remove dead code 2025-07-28 16:54:37 +10:00
Profiling Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
touchkeyboard refactor(windows): start move of help and hint 2020-02-23 17:49:33 +07:00
viskbd Apply suggestions from code review 2025-10-13 10:37:35 +02:00
.gitignore chore(windows): add compiled resources to .gitignore 2024-05-20 08:19:56 +07:00
build.sh maint(common): consolidate builder scripts 2025-08-02 08:11:24 +10:00
debug-manifest.in chore(windows): don't change debug-manifest 2020-12-19 07:50:50 +11:00
desktop.ini Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
GlobalKeyboardChangeManager.pas [Windows] Debug logging and proof of concept tests for keyboarding support within metro-style apps 2018-10-18 20:00:49 +11:00
icons.rc chore(windows): update resource references 2022-06-01 06:56:43 +10:00
icons.res Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
keyman.dpr feat(windows): automatic updates option to config reg 2024-09-09 15:51:32 +10:00
keyman.dproj feat(windows): automatic updates option to config reg 2024-09-09 15:51:32 +10:00
keyman.otares Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
Keyman.System.SharedBuffers.pas [Windows] Address review comments 2018-10-29 16:34:00 +11:00
KeymanDesktopShell.pas fix(windows): hint dialog was blank when elevated 2020-09-22 20:04:44 +10:00
KeymanHints.pas feat(windows): asynchronous hint window 2020-02-29 20:08:51 +07:00
KeymanMenuItem.pas [Developer] Render default language icon for imported keyboard automatically 2018-09-23 10:01:31 +10:00
keymanmenuitem.rc Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
keymanmenuitem_info.bmp Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
keymanmenuitem_selected.bmp Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
keymanmenutitle.bmp Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
KeymanTrayIcon.pas fix(windows): fix menu popup position 2020-12-19 07:31:17 +11:00
kmint.pas fix(windows): Improve shutdown robustness 2022-11-10 16:10:49 +11:00
main.pas feat(windows): review comments 2024-11-07 15:29:14 +10:00
manifest.in fix(windows): Rename to Keyman 2020-12-02 09:56:14 +11:00
manifest.rc Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
Menu_KeyboardItems.pas fix(windows): Rename to Keyman 2020-12-02 09:56:14 +11:00
menu_title.png Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
no_icon.bmp Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
no_icon.ico Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
osktoolbar.bmp Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
osktoolbar.rc Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
SortedKeyboardList.pas Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
tick.bmp Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00
UfrmKeyman7Main.dfm feat(windows): onlineupdatecheck references removed 2025-01-14 13:44:10 +10:00
UfrmKeyman7Main.pas fix(windows): reinstall low level keyboard hook if it gets removed 2025-11-17 16:30:43 +01:00
UfrmKeymanMenu.dfm fix(windows): fix menu popup position 2020-12-19 07:31:17 +11:00
UfrmKeymanMenu.pas fix(windows): fix menu popup position 2020-12-19 07:31:17 +11:00
version.rc chore(windows): move keymanversion.h to common 2022-06-12 13:56:13 +10:00
VistaMessages.pas Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121) 2017-07-25 10:53:06 +07:00