예제 #1
0
 private static void ReleaseAnsiKey(char ansiChar)
 {
     try
     {
         Key        key   = (Key)Enum.Parse(typeof(Key), ansiChar.ToString().ToUpper());
         Win32Input input = new Win32Input();
         input.type           = 1;
         input.ki             = new KBInput();
         input.ki.dwExtraInfo = IntPtr.Zero;
         input.ki.time        = 0;
         input.ki.wVk         = (ushort)KeyInterop.VirtualKeyFromKey(key);
         input.ki.wScan       = 0;
         input.ki.dwFlags     = 6;
         int i = 0;
         while (SendInput(1, ref input, Marshal.SizeOf(input)) <= 0)
         {
             if (i > 40)
             {
                 throw new TimeoutException("Could not press char " + ansiChar);
             }
             System.Threading.Thread.Sleep(25);
             i++;
         }
         System.Windows.Forms.Application.DoEvents();
     }
     catch (InvalidCastException)
     {
     }
 }
예제 #2
0
        private static void InjectLowMouseInput(MouseEvents evt, Point p)
        {
            Win32Input input = new Win32Input();

            input.type           = 0;
            input.mi             = new MouseInput();
            input.mi.dwExtraInfo = IntPtr.Zero;
            input.mi.mouseData   = 0;
            input.mi.time        = 0;
            input.mi.dx          = (int)(p.X * (65535f / Screen.PrimaryScreen.Bounds.Width));
            input.mi.dy          = (int)(p.Y * (65535f / Screen.PrimaryScreen.Bounds.Height));
            input.mi.dwFlags     = (uint)(evt | MouseEvents.MOVE | MouseEvents.ABSOLUTE | MouseEvents.VIRTUALDESK);

            if (SendInput(1, ref input, Marshal.SizeOf(input)) == 0)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
        }
예제 #3
0
        private static void ReleaseExtendedKey(Key key)
        {
            Win32Input input = new Win32Input();

            input.type           = 1;
            input.ki             = new KBInput();
            input.ki.dwExtraInfo = IntPtr.Zero;
            input.ki.time        = 0;
            input.ki.wVk         = (ushort)KeyInterop.VirtualKeyFromKey(key);
            input.ki.wScan       = 0;
            input.ki.dwFlags     = 3;
            int i = 0;

            while (SendInput(1, ref input, Marshal.SizeOf(typeof(Win32Input))) <= 0)
            {
                if (i > 40)
                {
                    throw new TimeoutException("Could not press char " + key);
                }
                System.Threading.Thread.Sleep(25);
                i++;
            }
            System.Windows.Forms.Application.DoEvents();
        }
예제 #4
0
        private static void ReleaseKey(char unicodeChar)
        {
            Win32Input input = new Win32Input();

            input.type           = 1;
            input.ki             = new KBInput();
            input.ki.dwExtraInfo = IntPtr.Zero;
            input.ki.time        = 0;
            input.ki.wVk         = 0;
            input.ki.wScan       = unicodeChar;
            input.ki.dwFlags     = 6;
            int i = 0;

            while (SendInput(1, ref input, Marshal.SizeOf(input)) <= 0)
            {
                if (i > 40)
                {
                    throw new TimeoutException("Could not press char " + unicodeChar);
                }
                System.Threading.Thread.Sleep(25);
                i++;
            }
            System.Windows.Forms.Application.DoEvents();
        }
예제 #5
0
 public static extern uint SendInput(uint nInputs, ref Win32Input pInputs, int cbSize);