Ejemplo n.º 1
0
 /// <summary>
 /// test if a key is pressed
 /// </summary>
 /// <example>
 /// <code>
 /// // test if F1 is currently pressed
 /// bool pressed = Keyboard.IsKeyDown(Keys.F1);
 /// </code>
 /// </example>
 /// <remarks>
 /// http://msdn.microsoft.com/en-us/library/system.windows.forms.keys
 /// </remarks>
 /// <param name="key">key</param>
 /// <returns>true/false</returns>
 public static Boolean IsKeyDown(Keys key)
 {
     return(NativeMethods.GetAsyncKeyState(key) == Int16.MinValue);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// removes the global hook
 /// </summary>
 /// <remarks>
 /// this is a private method. You cannot us it! See the constructor #ctor for an example.
 /// </remarks>
 private void unhook()
 {
     NativeMethods.UnhookWindowsHookEx(hhook);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// types a key or o sequence of keys to an application (by set the application to foreground)
 /// </summary>
 /// <example>
 /// <code>
 /// IntPtr hWnd = something;
 /// Keyboard.Type("{ENTER}",hWnd); // click the enter button
 /// Keyboard.Type("ENTER",hWnd);   // types "E","N","T","E","R"
 /// // or send it to a specific window
 /// </code>
 /// </example>
 /// <remarks>
 /// http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
 /// </remarks>
 /// <param name="Sequence">Sequence to type</param>
 /// <param name="hWnd">target application</param>
 /// <returns></returns>
 public static void Type(String Sequence, IntPtr hWnd)
 {
     NativeMethods.SetForegroundWindow((IntPtr)hWnd);
     SendKeys.SendWait(Sequence.Trim());
     SendKeys.Flush();
 }
Ejemplo n.º 4
0
        /// <remarks>
        /// this is a private method. You cannot us it! See the constructor #ctor for an example.
        /// </remarks>
        private void hook()
        {
            IntPtr hInstance = NativeMethods.LoadLibrary("User32");

            hhook = NativeMethods.SetWindowsHookEx(NativeMethods.WH_KEYBOARD_LL, SAFE_delegate_callback, hInstance, 0);
        }