We have some global keyboard hooks installed via SetWindowsHookEx
with WH_KEYBOARD_LL
that appear to randomly get unhooked by Windows.
We
I'm using the following project from: http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C to perform tasks when a certain key has been pressed.
I noticed that after i performed a task with a hotkey it stopped listening for new keypresses, i then changed the KeyboardHookListener to static and it seemed to solve my problem. I've no idea why this solved my problem, so feel free to comment on this!
My hotkey class:
class Hotkey
{
private static KeyboardHookListener _keyboardHookListener;
public void Start()
{
_keyboardHookListener = new KeyboardHookListener(new GlobalHooker()) { Enabled = true };
_keyboardHookListener.KeyDown += KeyboardListener_OnkeyPress;
}
private void KeyboardListener_OnkeyPress(object sender, KeyEventArgs e)
{
// Let's backup all projects
if (e.KeyCode == Keys.F1)
{
// Initialize files
var files = new Files();
// Backup all projects
files.BackupAllProjects();
}
// Quick backup - one project
else if (e.KeyCode == Keys.F2)
{
var quickBackupForm = new QuickBackup();
quickBackupForm.Show();
}
}
}