Exemplo n.º 1
0
        private void Grid_KeyDown(object sender, KeyEventArgs e)
        {
            String serverHost = tb_host.Text;

            if (serverHost.Length == 0)
            {
                TextBoxWriteLine("Error. IP/Host field is empty.");
                return;
            }
            int serverPort = 35197;

            if (int.TryParse(iUD_Port.Text, out serverPort) == false)
            {
                TextBoxWriteLine("Error. Invalid port number, using 35197");
                serverPort = 35197;
            }

            Key keyNative = e.Key;

            WindowsInput.Native.VirtualKeyCode keyModded = (WindowsInput.Native.VirtualKeyCode)((int)keyNative) + 22;
            if (((int)keyModded) >= 96 && ((int)keyModded) <= 105)
            {
                TextBoxWriteLine("Sending " + keyModded + " (" + (int)keyModded + ") to " + serverHost + ":" + serverPort);
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    client.SendUpdateRequest(keyModded, serverHost, serverPort);
                }).Start();
            }
            else
            {
                TextBoxWriteLine("Only numpad 0-9 supported");
            }
        }
Exemplo n.º 2
0
        public void SendUpdateRequest(WindowsInput.Native.VirtualKeyCode keyToSend, string hostServer, int portServer)
        {
            // Connect to a remote device.
            try
            {
                // Establish the remote endpoint for the socket.
                IPHostEntry ipHostInfo = Dns.GetHostEntry(hostServer);
                IPAddress   ipAddress  = ipHostInfo.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork);
                IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, portServer);

                // Create a TCP/IP socket.
                Socket client = new Socket(ipAddress.AddressFamily,
                                           SocketType.Stream, ProtocolType.Tcp);

                // StateObject
                StateObject state = new StateObject();
                state.workSocket = client;
                state.key        = keyToSend;
                // Connect to the remote endpoint.
                client.BeginConnect(remoteEP,
                                    new AsyncCallback(ConnectCallback), state);
            }
            catch (Exception e)
            {
                Console.WriteLine("StartClient " + e.ToString());
                mainWindow.Dispatcher.Invoke(() => // Update result window to allow user to continue
                {
                    mainWindow.TextBoxWriteLine("Error. Connection refused. Is the server running?");
                });
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Wait until the pixel changes its color to the specified one
        /// </summary>
        /// <param name="p">Database point</param>
        /// <param name="w">Target window rectangle</param>
        /// <param name="c">Target color</param>
        /// <param name="t">Cancellation token</param>
        /// <param name="k">Virtual key code for user abort</param>
        /// <param name="lim">Optional time limit (mS), 0 = no limit</param>
        /// <returns>False on timeout, true otherwise</returns>
        public static bool WaitForPixel(ClickPoint p, Rectangle w, Color c, CancellationTokenSource t,
                                        WindowsInput.Native.VirtualKeyCode k, int lim = 0)
        {
            Point d   = p.GetPoint(PointReference.TopLeft, w);
            int   cnt = 0;

            while (Native.GetPixelColor(d) != c) //This API has a high performance impact
            {
                Sleep(200);
                cnt += 200;
                if (lim > 0)
                {
                    if (lim <= cnt)
                    {
                        return(false);
                    }
                }
                if (t != null)
                {
                    if (t.IsCancellationRequested)
                    {
                        break;
                    }
                }
                if (CheckKeyPressed(k))
                {
                    break;
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create an new LogicalKeyEventArgs with the single keyCode value
        /// </summary>
        /// <param name="keyCode"></param>
        internal LogicalKeyEventArgs(WindowsInput.Native.VirtualKeyCode keyCode)
        {
            List <WindowsInput.Native.VirtualKeyCode> tempList = new List <WindowsInput.Native.VirtualKeyCode>();

            tempList.Add(keyCode);

            KeyCodes = tempList;
        }
Exemplo n.º 5
0
        private void NotifyMessage(MessageDefinition.KeyboardState keyboardState, WindowsInput.Native.VirtualKeyCode vKCode)
        {
            KeyBoardMessageReceivedEventArgs args = new KeyBoardMessageReceivedEventArgs {
                keyboardState = keyboardState, virtualKeyCode = vKCode
            };

            KeyBoardMessageReceived?.Invoke(this, args);
        }
Exemplo n.º 6
0
 public void SendKeyboardMessage(KeyboardState keyboardState, WindowsInput.Native.VirtualKeyCode virtualKeyCode)
 {
     lock (lookKeyboardMsg)
     {
         CustomMessage msg  = new CustomMessage(MessageType.KeyboardMessage, keyboardState, virtualKeyCode);
         byte[]        data = MessageConveter.MessageToByteArray(msg);
         this.socket.Send(data);
         WaitForMessageSendComplete();
     }
 }
Exemplo n.º 7
0
 private void Press_2(WindowsInput.Native.VirtualKeyCode key)
 {
     try
     {
         ////Press '2'
         inputSimulator.Keyboard.KeyDown(key);
         Thread.Sleep(time);
         inputSimulator.Keyboard.KeyUp(key);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 8
0
        private void cbbCaNhan_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cbbCaNhan.SelectedIndex)
            {
            case 0:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_1;
                return;

            case 1:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_2;
                return;

            case 2:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_3;
                return;

            case 3:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_4;
                return;

            case 4:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_5;
                return;

            case 5:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_6;
                return;

            case 6:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_7;
                return;

            case 7:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_8;
                return;

            case 8:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_9;
                return;

            case 9:
                key_canhan = WindowsInput.Native.VirtualKeyCode.VK_0;
                return;
            }
        }
        private static void rowNum(WindowsInput.Native.VirtualKeyCode x)
        {
            var simulator = new InputSimulator();

            simulator.Keyboard.TextEntry('a');
            simulator.Keyboard.KeyPress(x);
            simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            simulator.Keyboard.TextEntry('b');
            simulator.Keyboard.KeyPress(x);
            simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            simulator.Keyboard.TextEntry('c');
            simulator.Keyboard.KeyPress(x);
            simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            simulator.Keyboard.TextEntry('d');
            simulator.Keyboard.KeyPress(x);
            simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            simulator.Keyboard.TextEntry('e');
            simulator.Keyboard.KeyPress(x);
            simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            simulator.Keyboard.TextEntry('f');
            simulator.Keyboard.KeyPress(x);
            simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            simulator.Keyboard.TextEntry('g');
            simulator.Keyboard.KeyPress(x);
            simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            //simulator.Keyboard.TextEntry('h');
            //simulator.Keyboard.KeyPress(x);
            //simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            //simulator.Keyboard.TextEntry('i');
            //simulator.Keyboard.KeyPress(x);
            //simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

            //simulator.Keyboard.TextEntry('j');
            //simulator.Keyboard.KeyPress(x);
            //simulator.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);
        }
Exemplo n.º 10
0
        public void SimulateKeyUp(VirtualKeyCode keyCode)
        {
            switch (keyCode)
            {
            case VirtualKeyCode.CONTROL:
            case VirtualKeyCode.LCONTROL:
            case VirtualKeyCode.RCONTROL:
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.LCONTROL);
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.RCONTROL);
                break;

            case VirtualKeyCode.MENU:
            case VirtualKeyCode.LMENU:
            case VirtualKeyCode.RMENU:
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.MENU);
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.LMENU);
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.RMENU);
                break;

            case VirtualKeyCode.SHIFT:
            case VirtualKeyCode.LSHIFT:
            case VirtualKeyCode.RSHIFT:
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.SHIFT);
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.LSHIFT);
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.RSHIFT);
                break;

            case VirtualKeyCode.LWIN:
            case VirtualKeyCode.RWIN:
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.LWIN);
                InputSimulatorInstance.Keyboard.KeyUp(VirtualKeyCode.RWIN);
                break;

            default:
                InputSimulatorInstance.Keyboard.KeyUp(keyCode);
                break;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Compute all keys that would be affected by a key up event.
        /// </summary>
        /// <param name="keyCode"></param>
        /// <param name="detectedKeyUpCode"></param>
        /// <param name="detectedKeyUpKeyCommands"></param>
        /// <param name="skipKeyUpState"></param>
        private void ComputeAffectedKeyUp(VirtualKeyCode keyCode, HashSet <VirtualKeyCode> detectedKeyUpCode, HashSet <KeyCommand> detectedKeyUpKeyCommands, bool skipKeyUpState = false)
        {
            // Already processed check
            if (detectedKeyUpCode.Contains(keyCode))
            {
                return;
            }

            // Key registered check
            if (!KeyDownCommandRegistry.TryGetValue(keyCode, out var keyCommands))
            {
                return;
            }

            // Not down check
            if (!skipKeyUpState && !InputSimulatorInstance.InputDeviceState.IsKeyUp(keyCode))
            {
                return;
            }

            detectedKeyUpCode.Add(keyCode);
            detectedKeyUpKeyCommands.UnionWith(keyCommands);
            keyCommands.ForEach(cmd => cmd.KeyCodes.ForEach(kc => ComputeAffectedKeyUp(kc, detectedKeyUpCode, detectedKeyUpKeyCommands, true)));
        }
Exemplo n.º 12
0
 private static WindowsInput.Native.VirtualKeyCode convertKey(Keys key)
 {
     WindowsInput.Native.VirtualKeyCode ret = (WindowsInput.Native.VirtualKeyCode)((int)key);
     return(ret);
 }
Exemplo n.º 13
0
 public static bool CheckKeyPressed(WindowsInput.Native.VirtualKeyCode code)
 {
     return(simulatorInstance.InputDeviceState.IsHardwareKeyDown(code));
 }
Exemplo n.º 14
0
 public static void PressKey(WindowsInput.Native.VirtualKeyCode code)
 {
     simulatorInstance.Keyboard.KeyDown(code);
 }