Note that there are some explanatory texts on larger screens.

plurals
  1. POKeyboard hook stops working after using Remote desktop
    primarykey
    data
    text
    <p>I've the following problem:</p> <p>My global keyboard hook stops working after i start any Remote Desktop session, even if session is closed hook doesn't work at all.</p> <p>Here is code of my hook</p> <pre><code>public class KeyboardHooker : IDisposable { private IntPtr _hhook; private static User32.LowLevelKeyboardProc _delegate; public KeyboardHooker() { _delegate = new User32.LowLevelKeyboardProc(HookCallback); } public void SetHook() { if (IsHookSetted) return; using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { _hhook = User32.SetWindowsHookEx(User32.WH_KEYBOARD_LL, _delegate, Kernel32.GetModuleHandle(curModule.ModuleName), 0); } } public void ReleaseHook() { if (IsHookSetted) { User32.UnhookWindowsHookEx(_hhook); _hhook = IntPtr.Zero; } } public bool IsHookSetted { get { return _hhook != IntPtr.Zero; } } private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode &gt;= 0) { bool handled = false; switch (wParam.ToInt32()) { case Messages.WM_SYSKEYDOWN: case Messages.WM_KEYDOWN: int vkCode = Marshal.ReadInt32(lParam); Keys keys = ExtractKey(vkCode); RaiseKeyDown(keys, ref handled); break; case Messages.WM_SYSKEYUP: case Messages.WM_KEYUP: vkCode = Marshal.ReadInt32(lParam); keys = ExtractKey(vkCode); RaiseKeyUp(keys, ref handled); break; } if (handled) return IntPtr.Add(IntPtr.Zero, 1); } GC.KeepAlive(this); return User32.CallNextHookEx(_hhook, nCode, wParam, lParam); } private Keys ExtractKey(int wParam) { Keys key = (Keys)wParam; return key; } #region Events public event KeyEventHandler KeyDown; public event KeyEventHandler KeyUp; private void RaiseKeyUp(Keys keys, ref bool handled) { if (KeyUp != null) { KeyEventArgs e = new KeyEventArgs(keys); KeyUp(this, e); handled = e.Handled; } } private void RaiseKeyDown(Keys keys, ref bool handled) { if (KeyDown != null) { KeyEventArgs e = new KeyEventArgs(keys); KeyDown(this, e); handled = e.Handled; } } #endregion #region Implementation of IDisposable /// &lt;summary&gt; /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// &lt;/summary&gt; /// &lt;filterpriority&gt;2&lt;/filterpriority&gt; public void Dispose() { ReleaseHook(); } #endregion } </code></pre> <p>Does anybody know how to solve this problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload