Example #1
0
 /// <summary>Constructor if you already have a whole key.  Good for making a dereferenced copy.</summary>
 /// <param name="key">The already built key.</param>
 public Key(Key key)
 {
     _buttonCounter = 0;
     Vk = key.Vk;
     ShiftKey = key.ShiftKey;
     ShiftType = key.ShiftType;
 }
Example #2
0
		/// <summary>Default constructor for editting a key. Used for property grid.</summary>
		/// <param name="key">The key to be editted.</param>
		public SetKey(Key key)
		{
			InitializeComponent();
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.ControlBox = false;
			this.ShowInTaskbar = false;
			this.TopLevel = false;
			this.TopMost = true;
			this.acceptBtn.Visible = false;
			this.cancelBtn.Visible = false;
			this.FormBorderStyle = FormBorderStyle.None;
			this.key = key;

			foreach (Messaging.VKeys tempVK in Enum.GetValues(typeof(Messaging.VKeys)))
			{
				this.keyChoices.Items.Add(tempVK);
			}
			for (int i = 0x30; i < 0x40; i++)
			{
				this.shiftKeys.Items.Add((Messaging.VKeys)i);
			}
			if ((this.key.ShiftType & Messaging.ShiftType.ALT) == Messaging.ShiftType.ALT)
				this.altChkBox.Checked = true;
			if ((this.key.ShiftType & Messaging.ShiftType.CTRL) == Messaging.ShiftType.CTRL)
				this.ctrlChkBox.Checked = true;
			if ((this.key.ShiftType & Messaging.ShiftType.SHIFT) == Messaging.ShiftType.SHIFT)
				this.shiftChkBox.Checked = true;
			this.keyChoices.SelectedItem = key.Vk;
			this.shiftKeys.SelectedItem = key.ShiftKey;
		}
Example #3
0
 public Controller(Keyboard.Key UP, Keyboard.Key DOWN, Keyboard.Key LEFT, Keyboard.Key RIGHT)
 {
     MoveUp    = UP;
     MoveDown  = DOWN;
     MoveLeft  = LEFT;
     MoveRight = RIGHT;
 }
Example #4
0
 /// <summary>
 /// Tells the input class to begin tracking a key.
 /// </summary>
 /// <param name="k">The key to track.</param>
 public void TrackKey(Keyboard.Key k)
 {
     if (!RegisteredKeys.ContainsKey(k))
     {
         RegisteredKeys.Add(k, new MonitorKey());
     }
     //RegisteredKeys.Add(k, new MonitorKey());
 }
Example #5
0
    /// <summary>returns true, if the key is not pressed this frame and was pressed previous frame</summary>
    /// <param name="key">Key to be evaluated</param>
    /// <returns>returns true, if the key is not pressed this frame and was pressed previous frame</returns>
    public static bool Upward(Keyboard.Key key)
    {
        if (!isInitialized)
        {
            Initialize();
        }

        return(previousKeyIsPressed[(int)key] && !currentKeyIsPressed[(int)key]);
    }
Example #6
0
    /// <summary>
    /// Checks if a key is currently being held down.
    /// </summary>
    /// <param name="k">The key to check.</param>
    /// <returns>True if the key is being held down.</returns>
    public bool CheckKeyHeld(Keyboard.Key k)
    {
        if (!RegisteredKeys.ContainsKey(k))
        {
            return(false);
        }

        return(RegisteredKeys[k].Held);
    }
    public bool IsKeyPressed(Keyboard.Key key)
    {
        var kCode = UnityEngine.KeyCode.None;

        if (key == Keyboard.Key.Unknown)
        {
            return(true);
        }
        kCode = TransformKey(key, kCode);
        return(UnityEngine.Input.GetKey(kCode));
    }
 public MapVisualisation(World w, Keyboard.Key toggleKey, bool startEnabled, UpdateImage ui)
 {
     int width = w.Width;
     int height = w.Height;
     
     world = w;
     MapSprite = new Sprite(new Texture((uint)width, (uint)height));
     img = new Image((uint)width, (uint)height);
     updater = ui;
     ToggleKey = toggleKey;
     Enabled = startEnabled;
 }
Example #9
0
 public SoftKey(Key keyV, string upChar, string downChar, double posX, double posY, double width, double height)
 {
     this.keyValue = keyV;
     this.upChar = upChar;
     this.downChar = downChar;
     this.keyPosX = posX;
     this.keyPosY = posY;
     this.keyWidth = width;
     this.keyHeight = height;
     key = new Grid();
     key.Background = backgroundColor;
     key.Width = this.keyWidth;
     key.Height = this.keyHeight;
     Canvas.SetLeft(key, this.keyPosX);
     Canvas.SetTop(key, this.keyPosY);
     textBlock = new TextBlock();
     textBlock.FontSize = 20;
     if (this.downChar == null)
     {
         textBlock.Text = this.upChar;
     }
     else {
         textBlock.Text = upChar; //+ "\n\n" + downChar;
     }
     textBlock.Foreground = this.foregroundColor;
     textBlock.HorizontalAlignment = HorizontalAlignment.Center;
     textBlock.VerticalAlignment = VerticalAlignment.Center;
     key.Children.Add(textBlock);
     //
     if (this.keyValue == Key.CapsLock)
     {
         capsLockStatus = Console.CapsLock;
         key.Background = Console.CapsLock ? this.activeBackgroundColor : this.backgroundColor;
     }
     ///???????
     if (upChar.Length == 1 && upChar[0]>='A' && upChar[0]<='Z')
     {
         char name = upChar[0];
         name = Char.ToLower(name);
         Config.keyPosX.Add(name, this.keyPosX + keyWidth / 2);
         Config.keyPosY.Add(name, this.keyPosY + keyHeight / 2);
     }
     if (keyValue == Key.Tab || keyValue == Key.LeftShift || keyValue == Key.RightShift ||
         keyValue == Key.LeftAlt || keyValue == Key.RightAlt || keyValue == Key.LeftCtrl || keyValue == Key.RightCtrl)
     {
         this.isControlKey = true;
     } else
     {
         this.isControlKey = false;
     }
 }
Example #10
0
    /// <summary>
    /// Checks if the key has been pressed and released.
    /// </summary>
    /// <param name="k">The key to check.</param>
    /// <returns>Returns true if the key has been pressed.</returns>
    public bool CheckKeyPressed(Keyboard.Key k)
    {
        if (!RegisteredKeys.ContainsKey(k))
        {
            return(false);
        }

        if (RegisteredKeys[k].Pressed)
        {
            RegisteredKeys[k].Pressed = false;
            return(true);
        }
        else
        {
            return(false);
        }
    }
    private static KeyCode TransformKey(Keyboard.Key key, KeyCode kCode)
    {
        switch (key)
        {
        case Keyboard.Key.Space:
            kCode = UnityEngine.KeyCode.Space;
            break;

        case Keyboard.Key.W:
            kCode = UnityEngine.KeyCode.W;
            break;

        case Keyboard.Key.A:
            kCode = UnityEngine.KeyCode.A;
            break;

        case Keyboard.Key.S:
            kCode = UnityEngine.KeyCode.S;
            break;

        case Keyboard.Key.D:
            kCode = UnityEngine.KeyCode.D;
            break;

        case Keyboard.Key.Q:
            kCode = UnityEngine.KeyCode.Q;
            break;

        case Keyboard.Key.E:
            kCode = UnityEngine.KeyCode.E;
            break;

        case Keyboard.Key.R:
            kCode = UnityEngine.KeyCode.R;
            break;

        case Keyboard.Key.LShift:
            kCode = UnityEngine.KeyCode.LeftShift;
            break;
        }

        return(kCode);
    }
    public static List <char> getCharInput()
    {
        List <char> result = new List <char>();

        for (Keyboard.Key i = Keyboard.Key.A; i <= Keyboard.Key.Z; i++)
        {
            if (Downward(i))
            {
                if (IsPressed(Keyboard.Key.LShift) || IsPressed(Keyboard.Key.RShift))
                {
                    result.Add(KeyToChar(i));
                }
                else
                {
                    result.Add((char)(KeyToChar(i) + ('a' - 'A')));
                }
            }
        }
        return(result);
    }
    public static List <char> getNumberInput()
    {
        List <char> result = new List <char>();

        for (Keyboard.Key i = Keyboard.Key.Num0; i <= Keyboard.Key.Num9; i++)
        {
            if (Downward(i))
            {
                result.Add(NumberKeyToChar(i));
            }
        }
        for (Keyboard.Key i = Keyboard.Key.Numpad0; i <= Keyboard.Key.Numpad9; i++)
        {
            if (Downward(i))
            {
                result.Add(NumberKeyToChar(i));
            }
        }
        return(result);
    }
Example #14
0
		/// <summary>Default constructor, used in property grid.</summary>
		public SetKey()
		{
			InitializeComponent();
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.ControlBox = false;
			this.ShowInTaskbar = false;
			this.TopLevel = false;
			this.acceptBtn.Visible = false;
			this.cancelBtn.Visible = false;
			this.FormBorderStyle = FormBorderStyle.None;
			key = new Key();
			foreach (Messaging.VKeys vk in Enum.GetValues(typeof(Messaging.VKeys)))
			{
				this.keyChoices.Items.Add(vk);
			}
			for (int i = 0x30; i < 0x40; i++)
			{
				this.shiftKeys.Items.Add((Messaging.VKeys)i);
			}
		}
Example #15
0
		public static void BackgroundMouseClick(IntPtr hWnd, Key key, int x, int y, int delay = 100)
		{
			switch (key.Vk)
			{
				case VKeys.KEY_MBUTTON:
					PostMessage(hWnd, (int) Message.MBUTTONDOWN, (uint) key.Vk, GetLParam(x, y));
					Thread.Sleep(delay);
					PostMessage(hWnd, (int) Message.MBUTTONUP, (uint) key.Vk, GetLParam(x, y));
					break;
				case VKeys.KEY_LBUTTON:
					PostMessage(hWnd, (int) Message.LBUTTONDOWN, (uint) key.Vk, GetLParam(x, y));
					Thread.Sleep(delay);
					PostMessage(hWnd, (int) Message.LBUTTONUP, (uint) key.Vk, GetLParam(x, y));
					break;
				case VKeys.KEY_RBUTTON:
					PostMessage(hWnd, (int) Message.RBUTTONDOWN, (uint) key.Vk, GetLParam(x, y));
					Thread.Sleep(delay);
					PostMessage(hWnd, (int) Message.RBUTTONUP, (uint) key.Vk, GetLParam(x, y));
					break;
			}
		}
Example #16
0
 /// <summary>
 /// If the given key is clicked (pressed right NOW and NOT pressed last tick).
 /// </summary>
 /// <param name="key">Which key to be checked.</param>
 /// <returns>True if key is clicked, false otherwise.</returns>
 public bool isClicked(Keyboard.Key key)
 {
     return(currentKeys[(int)key] && !oldKeys[(int)key]);
 }
Example #17
0
		public static bool GetKeyState(Key key)
		{
			if ((GetKeyState((int) key.Vk) & 0xF0) == 1)
				return true;

			return false;
		}
Example #18
0
		public static bool SendMessage(IntPtr hWnd, Key key, bool checkKeyboardState, int delay = 100)
		{
			if (checkKeyboardState)
				CheckKeyShiftState();

			//Send KEY_DOWN
			if (SendMessage(hWnd, (int) Message.KEY_DOWN, (uint) key.Vk, GetLParam(1, key.Vk, 0, 0, 0, 0)))
				return false;
			Thread.Sleep(delay);

			//Send VM_CHAR
			if (SendMessage(hWnd, (int) Message.VM_CHAR, (uint) key.Vk, GetLParam(1, key.Vk, 0, 0, 0, 0)))
				return false;
			Thread.Sleep(delay);

			//Send KEY_UP
			if (SendMessage(hWnd, (int) Message.KEY_UP, (uint) key.Vk, GetLParam(1, key.Vk, 0, 0, 1, 1)))
				return false;
			Thread.Sleep(delay);

			return true;
		}
 public static char KeyToChar(Keyboard.Key key)
 {
     return((char)((int)key + (int)'A'));
 }
Example #20
0
		public static bool ForegroundKeyUp(Key key)
		{
			uint intReturn;
			INPUT structInput;
			structInput = new INPUT();
			structInput.type = INPUT_KEYBOARD;

			// Key down shift, ctrl, and/or alt
			structInput.ki.wScan = 0;
			structInput.ki.time = 0;
			structInput.ki.dwFlags = 0;
			// Key down the actual key-code
			structInput.ki.wVk = (ushort) key.Vk;

			// Key up the actual key-code
			structInput.ki.dwFlags = KEYEVENTF_KEYUP;
			intReturn = SendInput(1, ref structInput, Marshal.SizeOf(typeof (INPUT)));
			return true;
		}
Example #21
0
		public static bool ForegroundKeyPressAll(IntPtr hWnd, Key key, bool alt, bool ctrl, bool shift, int delay = 100)
		{
			if (GetForegroundWindow() != hWnd)
			{
				if (!SetForegroundWindow(hWnd))
					return false;
			}
			uint intReturn;
			INPUT structInput;
			structInput = new INPUT();
			structInput.type = INPUT_KEYBOARD;

			// Key down shift, ctrl, and/or alt
			structInput.ki.wScan = 0;
			structInput.ki.time = 0;
			structInput.ki.dwFlags = 0;
			if (alt)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_MENU;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (ctrl)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_CONTROL;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (shift)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_SHIFT;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);

				if (key.ShiftKey != VKeys.NULL)
				{
					structInput.ki.wVk = (ushort) key.ShiftKey;
					intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
					Thread.Sleep(delay);
				}
			}

			// Key up the actual key-code			
			ForegroundKeyPress(hWnd, key);

			structInput.ki.dwFlags = KEYEVENTF_KEYUP;
			if (shift && key.ShiftKey == VKeys.NULL)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_SHIFT;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (ctrl)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_CONTROL;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (alt)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_MENU;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			return true;
		}
 public static char NumberKeyToChar(Keyboard.Key key)
 {
     return((char)((key >= Keyboard.Key.Num0 && key <= Keyboard.Key.Num9) ?
                   ((int)key - (Keyboard.Key.Num0) + (int)'0') : ((int)key - (Keyboard.Key.Numpad0) + (int)'0')));
 }
Example #23
0
        private static void SendKeyboardInput(Key key, bool press)
        {
            PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
            permissions.Demand();

            NativeMethods.INPUT ki = new NativeMethods.INPUT();
            ki.type = NativeMethods.InputKeyboard;
            ki.union.keyboardInput.wVk = (short)KeyInterop.VirtualKeyFromKey(key);
            ki.union.keyboardInput.wScan = (short)NativeMethods.MapVirtualKey(ki.union.keyboardInput.wVk, 0);

            int dwFlags = 0;

            if (ki.union.keyboardInput.wScan > 0)
            {
                dwFlags |= NativeMethods.KeyeventfScancode;
            }

            if (!press)
            {
                dwFlags |= NativeMethods.KeyeventfKeyup;
            }

            ki.union.keyboardInput.dwFlags = dwFlags;

            if (ExtendedKeys.Contains(key))
            {
                ki.union.keyboardInput.dwFlags |= NativeMethods.KeyeventfExtendedkey;
            }

            ki.union.keyboardInput.time = 0;
            ki.union.keyboardInput.dwExtraInfo = new IntPtr(0);

            if (NativeMethods.SendInput(1, ref ki, Marshal.SizeOf(ki)) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Example #24
0
 /// <summary>
 /// Releases a key.
 /// </summary>
 /// <param name="key">The key to release.</param>
 public static void Release(Key key)
 {
     SendKeyboardInput(key, false);
 }
Example #25
0
 /// <summary>
 /// Wrapper to convert from a SFML key
 /// </summary>
 /// <param name="key">SFML key</param>
 /// <returns>Returns true if the key is down this frame
 /// and the key was not down the previous frame</returns>
 public bool IsKeyPressed(Keyboard.Key key)
 {
     return(IsKeyPressed((int)key));
 }
Example #26
0
 /// <summary>
 /// Presses down a key.
 /// </summary>
 /// <param name="key">The key to press.</param>
 public static void Press(Key key)
 {
     SendKeyboardInput(key, true);
 }
Example #27
0
 /// <summary>
 /// Checks if the given key is released. (Not pressed right now and pressed last tick).
 /// </summary>
 /// <param name="key">Which key to be checked.</param>
 /// <returns></returns>
 public bool isReleased(Keyboard.Key key)
 {
     return(oldKeys[(int)key] && !Keyboard.IsKeyPressed(key));
 }
Example #28
0
 /// <summary>
 /// If the given key is pressed right NOW.
 /// </summary>
 /// <param name="key">Which key to be checked.</param>
 /// <returns>True if the given key is pressed, false otherwise.</returns>
 public bool isPressed(Keyboard.Key key)
 {
     return(Keyboard.IsKeyPressed(key));
 }
Example #29
0
		public static bool ForegroundKeyPress(IntPtr hWnd, Key key, int delay = 100)
		{
			bool temp = true;

			temp &= ForegroundKeyDown(hWnd, key);
			Thread.Sleep(delay);
			temp &= ForegroundKeyUp(hWnd, key);
			Thread.Sleep(delay);
			return temp;
		}
Example #30
0
 public static bool IsPressed(Keyboard.Key key)
 {
     return(currentKeyIsPressed[(int)key]);
 }
Example #31
0
		public static bool ForegroundKeyDown(Key key)
		{
			uint intReturn;
			INPUT structInput;
			structInput = new INPUT();
			structInput.type = INPUT_KEYBOARD;

			// Key down shift, ctrl, and/or alt
			structInput.ki.wScan = 0;
			structInput.ki.time = 0;
			structInput.ki.dwFlags = 0;
			// Key down the actual key-code
			structInput.ki.wVk = (ushort) key.Vk;
			intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));

			// Key up shift, ctrl, and/or alt
			//keybd_event((int)key.VK, GetScanCode(key.VK) + 0x80, KEYEVENTF_NONE, 0);
			//keybd_event((int)key.VK, GetScanCode(key.VK) + 0x80, KEYEVENTF_KEYUP, 0);
			return true;
		}
Example #32
0
 /// <summary>
 /// Wrapper to convert from a SFML key
 /// </summary>
 /// <param name="key">The SFML key</param>
 /// <returns>Returns true if the key is down this frame</returns>
 public bool IsKeyDown(Keyboard.Key key)
 {
     return(IsKeyDown((int)key));
 }
Example #33
0
		public static bool ForegroundKeyUp(IntPtr hWnd, Key key)
		{
			if (GetForegroundWindow() != hWnd)
			{
				if (!SetForegroundWindow(hWnd))
					return false;
			}
			return ForegroundKeyUp(key);
		}
Example #34
0
        async Task AvoidOffline(IntPtr winHandle)
        {
            while (true)
            {
                // 以下是自动打怪的指令,还不成熟 me@20200109

                /*var x = mWowWindowList.Where(ou => ou.Ptr == winHandle.ToString()).Single();
                 * x.Status = "正在打怪中";
                 *
                 * var key_5 = new Keyboard.Key(Messaging.VKeys.KEY_5);
                 * var key_3 = new Keyboard.Key(Messaging.VKeys.KEY_3);
                 * var key_j = new Keyboard.Key(Messaging.VKeys.KEY_J);
                 * var key_6 = new Keyboard.Key(Messaging.VKeys.KEY_6);
                 * var key_w = new Keyboard.Key(Messaging.VKeys.KEY_W);
                 * var key_q = new Keyboard.Key(Messaging.VKeys.KEY_Q);
                 * var key_d = new Keyboard.Key(Messaging.VKeys.KEY_D);
                 *
                 * key_5.PressBackground(winHandle);
                 * await Task.Delay(500);
                 * key_j.PressBackground(winHandle);
                 * await Task.Delay(500);
                 * key_3.PressBackground(winHandle);
                 * await Task.Delay(1500);
                 * key_3.PressBackground(winHandle);
                 * await Task.Delay(1500);
                 * key_3.PressBackground(winHandle);
                 * await Task.Delay(1500);
                 * key_3.PressBackground(winHandle);
                 * await Task.Delay(1500);
                 * key_3.PressBackground(winHandle);
                 * await Task.Delay(1500);
                 * key_6.PressBackground(winHandle);
                 * await Task.Delay(1000);
                 * key_j.PressBackground(winHandle);
                 * await Task.Delay(1500);
                 *
                 * key_w.PressBackground(winHandle);
                 * key_q.PressBackground(winHandle);
                 * key_w.PressBackground(winHandle);
                 * key_q.PressBackground(winHandle);
                 * key_w.PressBackground(winHandle);
                 * key_q.PressBackground(winHandle);
                 * key_w.PressBackground(winHandle);
                 * key_q.PressBackground(winHandle);
                 * key_w.PressBackground(winHandle);
                 * key_q.PressBackground(winHandle);
                 * key_w.PressBackground(winHandle);
                 * key_q.PressBackground(winHandle);
                 *
                 * key_d.PressBackground(winHandle);
                 * key_d.PressBackground(winHandle);
                 * key_d.PressBackground(winHandle);
                 * key_d.PressBackground(winHandle);
                 * key_d.PressBackground(winHandle);*/



                var x = mWowWindowList.Where(ou => ou.Ptr == winHandle.ToString()).Single();
                x.Status = "正在战场中";

                var key_1     = new Keyboard.Key(Messaging.VKeys.KEY_1);
                var key_5     = new Keyboard.Key(Messaging.VKeys.KEY_5);
                var key_3     = new Keyboard.Key(Messaging.VKeys.KEY_3);
                var key_4     = new Keyboard.Key(Messaging.VKeys.KEY_4);
                var key_j     = new Keyboard.Key(Messaging.VKeys.KEY_J);
                var key_6     = new Keyboard.Key(Messaging.VKeys.KEY_6);
                var key_w     = new Keyboard.Key(Messaging.VKeys.KEY_W);
                var key_space = new Keyboard.Key(Messaging.VKeys.KEY_SPACE);
                var key_q     = new Keyboard.Key(Messaging.VKeys.KEY_Q);
                var key_d     = new Keyboard.Key(Messaging.VKeys.KEY_D);

                key_1.PressBackground(winHandle);
                await Task.Delay(1000);

                key_j.PressBackground(winHandle);
                await Task.Delay(3000);

                key_1.PressBackground(winHandle);
                await Task.Delay(1000);

                key_w.PressBackground(winHandle);
                key_w.PressBackground(winHandle);
                key_w.PressBackground(winHandle);
                key_w.PressBackground(winHandle);
                key_w.PressBackground(winHandle);
                key_space.PressBackground(winHandle);
                key_w.PressBackground(winHandle);
                key_space.PressBackground(winHandle);
                await Task.Delay(1000);

                key_q.PressBackground(winHandle);
                key_q.PressBackground(winHandle);
                key_3.PressBackground(winHandle);
                await Task.Delay(1000);
            }
        }
Example #35
0
		public static bool PostMessage(IntPtr hWnd, Key key, int delay = 100)
		{
			//Send KEY_DOWN
			if (PostMessage(hWnd, (int) Message.KEY_DOWN, (uint) key.Vk, GetLParam(1, key.Vk, 0, 0, 0, 0)))
				return false;
			Thread.Sleep(delay);
			//Send VM_CHAR
			if (PostMessage(hWnd, (int) Message.VM_CHAR, (uint) key.Vk, GetLParam(1, key.Vk, 0, 0, 0, 0)))
				return false;
			Thread.Sleep(delay);
			if (PostMessage(hWnd, (int) Message.KEY_UP, (uint) key.Vk, GetLParam(1, key.Vk, 0, 0, 0, 0)))
				return false;
			Thread.Sleep(delay);

			return true;
		}
Example #36
0
 public void setKey(Key key)
 {
     this.rawKey = key;
 }
Example #37
0
		public static bool SendMessageAll(IntPtr hWnd, Key key, bool alt, bool ctrl, bool shift, int delay = 100)
		{
			CheckKeyShiftState();
			uint intReturn;
			INPUT structInput = new INPUT {type = INPUT_KEYBOARD, ki = {wScan = 0, time = 0, dwFlags = 0}};

			// Key down shift, ctrl, and/or alt
			if (alt)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_MENU;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (ctrl)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_CONTROL;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (shift)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_SHIFT;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);

				if (key.ShiftKey != VKeys.NULL)
				{
					//Send KEY_DOWN
					if (SendMessage(hWnd, (int) Message.KEY_DOWN, (uint) key.Vk, GetLParam(1, key.ShiftKey, 0, 0, 0, 0)))
						return false;
					Thread.Sleep(delay);
				}
			}

			SendMessage(hWnd, key, false);

			structInput.ki.dwFlags = KEYEVENTF_KEYUP;
			if (shift && key.ShiftKey == VKeys.NULL)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_SHIFT;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (ctrl)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_CONTROL;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}
			if (alt)
			{
				structInput.ki.wVk = (ushort) VKeys.KEY_MENU;
				intReturn = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
				Thread.Sleep(delay);
			}

			return true;
		}
Example #38
0
 /* public void addLog(LogType logType, Point pos, int id)
  {
      LogRecord record = new LogRecord(logType, pos);
      record.setId(id);
      record.setInclinometerReading(this.inclinometer.GetCurrentReading());
      record.setAccelerometerReading(this.accelerometer.GetCurrentReading());
      record.setGyrometerReading(this.gyrometer.GetCurrentReading());
      record.setLightSensorReading(this.lightsensor.GetCurrentReading());
      this.logList.Add(record);
      
  }*/
  public void addLog(LogType logType, Point pos, int id, int handId, Key rawKey = Key.None)
  {
      if (Config.collectDataStatus == CollectDataStatus.Started)
      {
          LogRecord record = new LogRecord(logType, pos, handId);
          record.setId(id);
          if (isBehavior)
          {
              record.setDest(this.tasks.getCurrentDest());
              record.setInclinometerReading(this.inclinometer.GetCurrentReading());
              record.setAccelerometerReading(this.accelerometer.GetCurrentReading());
              record.setGyrometerReading(this.gyrometer.GetCurrentReading());
          }
          else
          {
              record.setDest(this.tasks.getCurrentDest());
              record.setKey(rawKey);
              record.setPredictHints(this.wordPredictor.getPredictHints());
          }
          this.logList.Add(record);
          //this.statusAnalyzer.addLog(record);
          if (logType == LogType.TouchDown)
          {
              this.statusAnalyzer.addLog(record);
          }
      }
  }
Example #39
0
 /// <summary>
 /// Performs a press-and-release operation for the specified key, which is effectively equivallent to typing.
 /// </summary>
 /// <param name="key">The key to press.</param>
 public static void Type(Key key)
 {
     Press(key);
     Release(key);
 }
Example #40
0
 /// <summary>
 /// Tells the input class to stop tracking a key.
 /// </summary>
 /// <param name="k">The key to stop tracking.</param>
 public void UntrackKey(Keyboard.Key k)
 {
     RegisteredKeys.Remove(k);
 }
Example #41
0
		/// <summary>Constructor for key bindings not in a property grid.</summary>
		/// <param name="p">Where the form should load.</param>
		/// <param name="key">The key to be editted.</param>
		public SetKey(Point p, Key key)
		{
			InitializeComponent();
			this.key = key;
			this.TopMost = true;
			foreach (Messaging.VKeys tempVK in Enum.GetValues(typeof(Messaging.VKeys)))
			{
				this.keyChoices.Items.Add(tempVK);
			}
			for (int i = 0x30; i < 0x3A; i++)
			{
				this.shiftKeys.Items.Add((Messaging.VKeys)i);
			}
			if ((this.key.ShiftType & Messaging.ShiftType.ALT) == Messaging.ShiftType.ALT)
				this.altChkBox.Checked = true;
			if ((this.key.ShiftType & Messaging.ShiftType.CTRL) == Messaging.ShiftType.CTRL)
				this.ctrlChkBox.Checked = true;
			if ((this.key.ShiftType & Messaging.ShiftType.SHIFT) == Messaging.ShiftType.SHIFT)
				this.shiftChkBox.Checked = true;
			this.keyChoices.SelectedItem = this.key.Vk;
			this.shiftKeys.SelectedItem = key.ShiftKey;
		}
Example #42
0
        /// <summary>
        /// Types a key while a set of modifier keys are being pressed. Modifer keys
        /// are pressed in the order specified and released in reverse order.
        /// </summary>
        /// <param name="key">Key to type.</param>
        /// <param name="modifierKeys">Set of keys to hold down with key is typed.</param>
        private static void Type(Key key, Key[] modifierKeys)
        {
            foreach (Key modiferKey in modifierKeys)
            {
                Press(modiferKey);
            }

            Type(key);

            foreach (Key modifierKey in modifierKeys.Reverse())
            {
                Release(modifierKey);
            }
        }