@@ -32,7 +32,7 @@ public KeyboardListener(frmSuperPutty form, GlobalHotkeys hotkeys)
32
32
this . dispatcher = Dispatcher . CurrentDispatcher ;
33
33
34
34
// We have to store the LowLevelKeyboardProc, so that it is not garbage collected runtime
35
- hookedLowLevelKeyboardProc = ( InterceptKeys . LowLevelKeyboardProc ) LowLevelKeyboardProc ;
35
+ hookedLowLevelKeyboardProc = ( WinAPI . LowLevelKeyboardProc ) LowLevelKeyboardProc ;
36
36
37
37
// Set the hook
38
38
hookId = InterceptKeys . SetHook ( hookedLowLevelKeyboardProc ) ;
@@ -118,7 +118,7 @@ private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
118
118
}
119
119
}
120
120
121
- return InterceptKeys . CallNextHookEx ( hookId , nCode , wParam , lParam ) ;
121
+ return WinAPI . CallNextHookEx ( hookId , nCode , wParam , lParam ) ;
122
122
}
123
123
124
124
/// <summary>
@@ -129,7 +129,7 @@ private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
129
129
/// <summary>
130
130
/// Contains the hooked callback in runtime.
131
131
/// </summary>
132
- private InterceptKeys . LowLevelKeyboardProc hookedLowLevelKeyboardProc ;
132
+ private WinAPI . LowLevelKeyboardProc hookedLowLevelKeyboardProc ;
133
133
134
134
/// <summary>
135
135
/// HookCallbackAsync procedure that calls accordingly the KeyDown or KeyUp events.
@@ -176,7 +176,7 @@ void KeyboardListener_KeyboardCallbackAsync(InterceptKeys.KeyEvent keyEvent, int
176
176
/// </summary>
177
177
public void Dispose ( )
178
178
{
179
- InterceptKeys . UnhookWindowsHookEx ( hookId ) ;
179
+ WinAPI . UnhookWindowsHookEx ( hookId ) ;
180
180
}
181
181
182
182
#endregion
@@ -245,7 +245,6 @@ public RawKeyEventArgs(int VKCode, bool isSysKey, string Character)
245
245
/// </summary>
246
246
internal static class InterceptKeys
247
247
{
248
- public delegate IntPtr LowLevelKeyboardProc ( int nCode , UIntPtr wParam , IntPtr lParam ) ;
249
248
public static int WH_KEYBOARD_LL = 13 ;
250
249
251
250
/// <summary>
@@ -274,68 +273,32 @@ public enum KeyEvent : int
274
273
WM_SYSKEYDOWN = 260
275
274
}
276
275
277
- public static IntPtr SetHook ( LowLevelKeyboardProc proc )
276
+ public static IntPtr SetHook ( WinAPI . LowLevelKeyboardProc proc )
278
277
{
279
278
using ( Process curProcess = Process . GetCurrentProcess ( ) )
280
279
using ( ProcessModule curModule = curProcess . MainModule )
281
280
{
282
- return SetWindowsHookEx ( WH_KEYBOARD_LL , proc , GetModuleHandle ( curModule . ModuleName ) , 0 ) ;
281
+ return WinAPI . SetWindowsHookEx ( WH_KEYBOARD_LL , proc , WinAPI . GetModuleHandle ( curModule . ModuleName ) , 0 ) ;
283
282
}
284
283
}
285
284
286
- [ DllImport ( "user32.dll" , CharSet = CharSet . Auto , SetLastError = true ) ]
287
- public static extern IntPtr SetWindowsHookEx ( int idHook , LowLevelKeyboardProc lpfn , IntPtr hMod , uint dwThreadId ) ;
288
-
289
- [ DllImport ( "user32.dll" , CharSet = CharSet . Auto , SetLastError = true ) ]
290
- [ return : MarshalAs ( UnmanagedType . Bool ) ]
291
- public static extern bool UnhookWindowsHookEx ( IntPtr hhk ) ;
292
-
293
- [ DllImport ( "user32.dll" , CharSet = CharSet . Auto , SetLastError = true ) ]
294
- public static extern IntPtr CallNextHookEx ( IntPtr hhk , int nCode , UIntPtr wParam , IntPtr lParam ) ;
295
-
296
- [ DllImport ( "kernel32.dll" , CharSet = CharSet . Auto , SetLastError = true ) ]
297
- public static extern IntPtr GetModuleHandle ( string lpModuleName ) ;
298
-
299
285
#region Convert VKCode to string
300
286
// Note: Sometimes single VKCode represents multiple chars, thus string.
301
287
// E.g. typing "^1" (notice that when pressing 1 the both characters appear,
302
288
// because of this behavior, "^" is called dead key)
303
289
304
- [ DllImport ( "user32.dll" ) ]
305
- private static extern int ToUnicodeEx ( uint wVirtKey , uint wScanCode , byte [ ] lpKeyState , [ Out , MarshalAs ( UnmanagedType . LPWStr ) ] System . Text . StringBuilder pwszBuff , int cchBuff , uint wFlags , IntPtr dwhkl ) ;
306
-
307
- [ DllImport ( "user32.dll" ) ]
308
- private static extern bool GetKeyboardState ( byte [ ] lpKeyState ) ;
309
-
310
- [ DllImport ( "user32.dll" ) ]
311
- private static extern uint MapVirtualKeyEx ( uint uCode , uint uMapType , IntPtr dwhkl ) ;
312
-
313
- [ DllImport ( "user32.dll" , CharSet = CharSet . Auto , ExactSpelling = true ) ]
314
- private static extern IntPtr GetKeyboardLayout ( uint dwLayout ) ;
315
-
316
- [ DllImport ( "User32.dll" ) ]
317
- private static extern IntPtr GetForegroundWindow ( ) ;
318
-
319
- [ DllImport ( "User32.dll" ) ]
320
- private static extern uint GetWindowThreadProcessId ( IntPtr hWnd , out uint lpdwProcessId ) ;
321
-
322
- [ DllImport ( "user32.dll" ) ]
323
- private static extern bool AttachThreadInput ( uint idAttach , uint idAttachTo , bool fAttach ) ;
324
290
325
- [ DllImport ( "kernel32.dll" ) ]
326
- private static extern uint GetCurrentThreadId ( ) ;
327
-
328
- private static uint lastVKCode = 0 ;
329
- private static uint lastScanCode = 0 ;
330
- private static byte [ ] lastKeyState = new byte [ 255 ] ;
331
- private static bool lastIsDead = false ;
332
291
333
292
// The reason to not use this at all is because there's a bug in here somewhere.
334
293
// The purpose of this function is to get the character that was pressed. The problem
335
294
// is that somewhere along the way, in certain conditions dealing with our code, it takes
336
295
// the focus away from an active window that is not ours. Look at usage at line ~100
337
296
// to see how it is used.
338
297
#if FALSE
298
+ private static uint lastVKCode = 0 ;
299
+ private static uint lastScanCode = 0 ;
300
+ private static byte [ ] lastKeyState = new byte [ 255 ] ;
301
+ private static bool lastIsDead = false ;
339
302
340
303
/// <summary>
341
304
/// Convert VKCode to Unicode.
0 commit comments