예제 #1
1
        private static char? ToChar(VirtualKey key, bool shift)
        {
            // convert virtual key to char
            if (32 == (int)key)
                return ' ';

            VirtualKey search;

            // look for simple letter
            foreach (var letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
            {
                if (Enum.TryParse<VirtualKey>(letter.ToString(), out search) && search.Equals(key))
                    return (shift) ? letter : letter.ToString().ToLower()[0];
            }

            // look for simple number
            foreach (var number in "1234567890")
            {
                if (Enum.TryParse<VirtualKey>("Number" + number.ToString(), out search) && search.Equals(key))
                    return number;
            }

            // not found
            return null;
        }
예제 #2
0
 public static bool IsLetter(VirtualKey key)
 {
     switch (key)
     {
         case VirtualKey.A:
         case VirtualKey.B:
         case VirtualKey.C:
         case VirtualKey.D:
         case VirtualKey.E:
         case VirtualKey.F:
         case VirtualKey.G:
         case VirtualKey.H:
         case VirtualKey.I:
         case VirtualKey.J:
         case VirtualKey.K:
         case VirtualKey.L:
         case VirtualKey.M:
         case VirtualKey.N:
         case VirtualKey.O:
         case VirtualKey.P:
         case VirtualKey.Q:
         case VirtualKey.R:
         case VirtualKey.S:
         case VirtualKey.T:
         case VirtualKey.U:
         case VirtualKey.V:
         case VirtualKey.W:
         case VirtualKey.X:
         case VirtualKey.Y:
         case VirtualKey.Z:
         case VirtualKey.Space:
             return true;
     }
     return false;
 }
예제 #3
0
 public KeyInput(IntPtr hkl, VirtualKey virtualKey)
 {
     this.m_sc = NativeMethods.MapVirtualKeyExWrapper((uint)virtualKey, MapVirtualKeyMapTypes.MAPVK_VK_TO_VSC_EX, hkl);
     this.m_hkl = hkl;
     this.m_vk = (uint)virtualKey;
     InterrogateKeyboardLayout(this.m_hkl, this.m_vk, this.m_sc);
 }
예제 #4
0
        public static bool IsNumeric(VirtualKey key, bool checkModifiers = true)
        {
            if (checkModifiers && Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down))
                return false;

            switch (key)
            {
                case VirtualKey.NumberPad0:
                case VirtualKey.NumberPad1:
                case VirtualKey.NumberPad2:
                case VirtualKey.NumberPad3:
                case VirtualKey.NumberPad4:
                case VirtualKey.NumberPad5:
                case VirtualKey.NumberPad6:
                case VirtualKey.NumberPad7:
                case VirtualKey.NumberPad8:
                case VirtualKey.NumberPad9:
                case VirtualKey.Number0:
                case VirtualKey.Number1:
                case VirtualKey.Number2:
                case VirtualKey.Number3:
                case VirtualKey.Number4:
                case VirtualKey.Number5:
                case VirtualKey.Number6:
                case VirtualKey.Number7:
                case VirtualKey.Number8:
                case VirtualKey.Number9:
                    return true;
            }

            return false;
        }
예제 #5
0
        public bool IsHolding( VirtualKey K )
        {
            if( HoldingKeys.ContainsKey( K ) )
                return HoldingKeys[ K ];

            return false;
        }
        public static bool IsValidHexDigitKey(VirtualKey key)
        {
            bool ret =  (key >= VirtualKey.Number0 && key <= VirtualKey.Number9) ||
                (key >= VirtualKey.A && key <= VirtualKey.F);

            return ret;
        }
예제 #7
0
 //not sure if I like this pattern
 public void Input(VirtualKey keypress)
 {
     if (keyWaiter != null)
     {
         keyWaiter.TrySetResult(keypress);
     }
 }
예제 #8
0
 public static extern int ToUnicodeEx(
     uint wVirtKey,
     uint wScanCode,
     VirtualKey[] lpKeyState,
     StringBuilder pwszBuff,
     int cchBuff,
     uint wFlags,
     IntPtr dwhkl);
예제 #9
0
 private bool IsNumberKey(VirtualKey inKey)
 {
     if (inKey < VirtualKey.Number0 || inKey > VirtualKey.Number9 && inKey < VirtualKey.NumberPad0 || inKey > VirtualKey.NumberPad9)
     {
         return false;
     }
     return true;
 }
 public void KeyDown(VirtualKey vk)
 {
     switch (vk)
     {
         case VirtualKey.Enter:
             if (Select != null) { Select(); }
             break;
     }
 }
예제 #11
0
 public static string MakeKeyboardSendKeyEventCommand(VirtualKey key)
 {
     var args = new KeyboardSendKeyEventArgs()
     {
         Key         = key,
     };
     var argsSerialize = JsonConvert.SerializeObject(args);
     return PluginCommandSerializeMaker.MakeCommand(InnerPluginName, "KeyboardSendKeyEvent", argsSerialize);
 }
예제 #12
0
 public KeyBind(VirtualKey mainKey,string commandCode)
 {
     this.MainKey = mainKey;
     IsMainKeyOnly = true;
     IsOptionKeyDown = false;
     IsCallBackOn = false;
     
     this.CommandCode = commandCode;
 }
예제 #13
0
        /// <summary>
        /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS.
        /// </summary>
        /// <param name="keyCode">The <see cref="VirtualKey"/> to press</param>
        public void KeyPress(VirtualKey keyCode)
        {
            var inputList =
                new InputBuilder()
                    .AddKeyDown(keyCode)
                    .AddKeyUp(keyCode)
                    .ToArray();

            SendSimulatedInput(inputList);
        }
    public static void SetVirtualKey(string keyName, float sensitivity = 3f, float gravity = 3f, float deadZone = 0.01f) {
        if(LookupVirtualKeyIndex(keyName) != -1) {
            Debug.LogWarning("That key is already defined: (" + keyName + ")");
            return;
        }

        int index = GetFirstOpenKeySpot();
        virtualKeys[index] = new VirtualKey(keyName, sensitivity, gravity, deadZone);
        virtualKeysStaged[index] = new VirtualKey(keyName, sensitivity, gravity, deadZone);
        virtualKeyIndexers.Add(index);
    }
예제 #15
0
 public static string MakeKeyboardEventCommand(VirtualKey key, byte scan, uint flag, uint extraInfo)
 {
     var args = new KeyboardEventArgs()
     {
         Key         = key,
         ScanKey     = scan,
         Flag        = flag,
         ExtraInfo   = extraInfo,
     };
     var argsSerialize = JsonConvert.SerializeObject(args);
     return PluginCommandSerializeMaker.MakeCommand(InnerPluginName, "KeyboardEvent", argsSerialize);
 }
예제 #16
0
        public static void InitCommands(TextBox input, VirtualKey acceptKey)
        {
            if (acceptKey == VirtualKey.Enter)
            {
                string[] line = input.Text.Split(new string[] { " " }, StringSplitOptions.None);
                string[] args = new string[line.Length - 1];
                Array.Copy(line, 1, args, 0, line.Length - 1);

                if (CommandHandlers.ContainsKey(line[0].ToLower()))
                    CommandHandlers[line[0].ToLower()].Invoke(args);
            }
        }
예제 #17
0
        public static bool IsModifier(VirtualKey key)
        {
            switch (key)
            {
                case VirtualKey.Shift:
                case VirtualKey.Control:
                case VirtualKey.Tab:
                case VirtualKey.Enter:
                    return true;
            }

            return false;
        }
예제 #18
0
		public static bool IsRelevantKey(VirtualKey key)
		{
			switch (key)
			{
				case VirtualKey.A:
				case VirtualKey.D:
				case VirtualKey.Space:
				case VirtualKey.Enter:
				case VirtualKey.R:
					return true;
				default:
					return false;
			}
		}
 public void KeyDown(VirtualKey vk)
 {
     switch (vk)
     {
         case VirtualKey.Down:
             ScrollDown();
             break;
         case VirtualKey.Up:
             ScrollUp();
             break;
         default:
             if (SelectedItem != null) { SelectedItem.KeyDown(vk); }
             break;
     }
 }
예제 #20
0
 private KeyboardEventArgs KeyboardEventArgs(VirtualKey key)
 {
     var alt = (win.GetKeyState(VirtualKey.Menu) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
     var shift = (win.GetKeyState(VirtualKey.Shift) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
     var control = (win.GetKeyState(VirtualKey.Control) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
     var windows = ((win.GetKeyState(VirtualKey.LeftWindows) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down)
         || ((win.GetKeyState(VirtualKey.RightWindows) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down);
     return new KeyboardEventArgs
     {
         AltKey = alt,
         ControlKey = control,
         ShiftKey = shift,
         WindowsKey = windows,
         VirtualKey = key,
         Character = ToChar(key, shift),
     };
 }
예제 #21
0
		public void KeyUp(VirtualKey key)
		{
			switch (key)
			{
				case VirtualKey.A:
					this.LeftKeyPressed = false;
					break;
				case VirtualKey.D:
					this.RightKeyPressed = false;
					break;
				case VirtualKey.Space:
					this.SpaceKeyPressed = false;
					break;
				case VirtualKey.Enter:
					this.EnterKeyPressed = false;
					break;
				case VirtualKey.R:
					this.RKeyPressed = false;
					break;
			}
		}
예제 #22
0
        public bool CheckKeyDown(VirtualKey key)
        {

            if (IsMainKeyOnly == false)
            {
                if (IsOptionKeyDown == false && OptionKey == key)
                {
                    IsOptionKeyDown = true;

                }


                if (IsOptionKeyDown && key == MainKey && IsCallBackOn == false)
                {
                    IsCallBackOn = true;
                    return true;

                }
                else
                {
                    return false;
                }

               
            }
            else
            {
                if (key == MainKey && IsCallBackOn == false)
                {
                    IsCallBackOn = true;
                    return true;

                }
                else
                {
                    return false;
                }
            }

        }
예제 #23
0
        public InputType? KeyToPossibleInputType(VirtualKey key)
        {
            switch (key)
            {
                //case VirtualKey.Space:
                //case VirtualKey.Enter:
                //case VirtualKey.Z:
                //case VirtualKey.X:
                //case VirtualKey.LeftControl:
                //case VirtualKey.RightControl:
                //    return InputType.Space;

                case VirtualKey.Up:
                case VirtualKey.W:
                    return InputType.Up;

                case VirtualKey.Down:
                case VirtualKey.S:
                    return InputType.Down;

                case VirtualKey.Left:
                case VirtualKey.A:
                    return InputType.Left;

                case VirtualKey.Right:
                case VirtualKey.D:
                    return InputType.Right;

                case VirtualKey.Pause:
                case VirtualKey.Menu:
                case VirtualKey.P:
                case VirtualKey.M:
                    return InputType.Pause;
            }

            return null;
        }
예제 #24
0
 public static Input.Key ToKey(this VirtualKey virtualKey)
 {
     return((Input.Key)System.Windows.Input.KeyInterop.KeyFromVirtualKey((int)virtualKey));
 }
예제 #25
0
 public static extern uint MapVirtualKeyEx(VirtualKey uCode, VirtualKeyMapType uMapType, IntPtr dwhkl);
예제 #26
0
 protected KeyPress Ctrl(VirtualKey virtualKey)
 => new KeyPress(virtualKey, ShiftState.Ctrl);
예제 #27
0
 protected KeyPress Alt(VirtualKey virtualKey)
 => new KeyPress(virtualKey, ShiftState.Alt);
예제 #28
0
        public static async Task <KeyDownProcessResult> KeyDown(VirtualKey key, bool shiftPressed, bool ctrlPressed, bool altPressed, WebViewController controller, Controls.NowPlayingView nowPlaying)
        {
            if (key == VirtualKey.Space)
            {
                // Play/Pause
                await controller.PlayPause();
            }
            else if (key == VirtualKey.Right && ctrlPressed)
            {
                // Next Track
                await controller.NextTrack();

                if (nowPlaying.IsOpen)
                {
                    nowPlaying.PlayChangeTrackAnimation(reverse: false);
                }
            }
            else if (key == VirtualKey.Left && ctrlPressed)
            {
                // Prev Track
                await controller.PreviousTrack();

                if (nowPlaying.IsOpen)
                {
                    nowPlaying.PlayChangeTrackAnimation(reverse: true);
                }
            }
            else if (key == VirtualKey.Up && ctrlPressed & shiftPressed)
            {
                // Max volume
                await controller.SeekVolume(1.0);
            }
            else if (key == VirtualKey.Down && ctrlPressed && shiftPressed)
            {
                // Mute
                await controller.SeekVolume(0.0);
            }
            else if (key == VirtualKey.Up && ctrlPressed)
            {
                // Volume up
                var newVolume = Math.Min(PlayStatusTracker.LastPlayStatus.Volume + 0.1, 1.0);
                await controller.SeekVolume(newVolume);

                PlayStatusTracker.LastPlayStatus.Volume = newVolume;
            }
            else if (key == VirtualKey.Down && ctrlPressed)
            {
                // Volume down
                var newVolume = Math.Max(PlayStatusTracker.LastPlayStatus.Volume - 0.1, 0.0);
                await controller.SeekVolume(newVolume);

                PlayStatusTracker.LastPlayStatus.Volume = newVolume;
            }
            else if (key == VirtualKey.Left && altPressed)
            {
                // Back
                return(KeyDownProcessResult.GoBack);
            }
            else if (key == VirtualKey.Escape)
            {
                // Back
                return(KeyDownProcessResult.GoBack);
            }
            else if (key == VirtualKey.M && ctrlPressed && nowPlaying.IsOpen && nowPlaying.ViewMode == Controls.NowPlayingView.NowPlayingViewMode.Normal)
            {
                await nowPlaying.SwitchToMiniView();
            }
            else if (key == VirtualKey.Left || key == VirtualKey.Right || key == VirtualKey.Up || key == VirtualKey.Down)
            {
                // Do nothing, but don't switch out of now playing either.
            }
            else
            {
                return(KeyDownProcessResult.AskJs);
            }
            return(KeyDownProcessResult.Handled);
        }
예제 #29
0
        private void LetterButtonClick(object sender, RoutedEventArgs e)
        {
            VirtualKey key = sender as VirtualKey;

            if (key == null || ReferenceTextBox == null)
            {
                return;
            }

            string letter = key.GetKey();
            int    length = ReferenceTextBox.Text.Length;

            //Special case
            if (key.Key == Windows.System.VirtualKey.Back)
            {
                if (length > 0)
                {
                    ReferenceTextBox.Text = ReferenceTextBox.Text.Remove(length - 1, 1);
                }
            }
            else if (key.Key == Windows.System.VirtualKey.Space)
            {
                ReferenceTextBox.Text += " ";
            }
            else if (key.Key == Windows.System.VirtualKey.LeftShift)
            {
                if (!_leftShiftEnabled)
                {
                    _leftShuftKey            = key;
                    _leftShiftPreviousColor  = _leftShuftKey.Background;
                    _leftShuftKey.Background = new SolidColorBrush(Colors.LightBlue);
                    _leftShiftEnabled        = true;
                }
                else
                {
                    _leftShuftKey.Background = _leftShiftPreviousColor;
                    _leftShiftEnabled        = false;
                }
                return;
            }
            else
            {
                //Always start as lower
                letter = letter.ToLower();

                if (_leftShiftEnabled)
                {
                    if (key.HasShiftKey)
                    {
                        letter = key.GetShiftKey();
                    }
                    else
                    {
                        letter = letter.ToUpper();
                    }
                }

                ReferenceTextBox.Text += letter;
            }

            if (_leftShuftKey != null &&
                _leftShiftPreviousColor != null)
            {
                _leftShuftKey.Background = _leftShiftPreviousColor;
            }
            _leftShiftEnabled = false;
        }
예제 #30
0
 /// <summary>
 /// Determines whether a key is up or down at the time the function is called by calling the GetAsyncKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)
 /// </summary>
 /// <param name="keyCode">The key code.</param>
 /// <returns>
 /// 	<c>true</c> if the key is down; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 /// The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling 
 /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped.
 /// 
 /// Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon.
 /// 
 /// You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. 
 /// 
 /// Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. 
 /// 
 /// Code Meaning 
 /// VK_LSHIFT Left-shift key. 
 /// VK_RSHIFT Right-shift key. 
 /// VK_LCONTROL Left-control key. 
 /// VK_RCONTROL Right-control key. 
 /// VK_LMENU Left-menu key. 
 /// VK_RMENU Right-menu key. 
 /// 
 /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. 
 /// </remarks>
 public static bool IsKeyDownAsync(VirtualKey keyCode)
 {
     Int16 result = GetAsyncKeyState((UInt16)keyCode);
     return (result < 0);
 }
예제 #31
0
 public static bool IsKeyPressed(VirtualKey virtualKey)
 {
     return(GetKeyState(virtualKey).HasFlag(KeyState.Pressed));
 }
예제 #32
0
        /// <summary>
        /// Calls the Win32 SendInput method to simulate a Key UP.
        /// </summary>
        /// <param name="keyCode">The VirtualKeyCode to lift up</param>
        public static void SimulateKeyUp(VirtualKey keyCode)
        {
            var up = new INPUT();
            up.Type = (UInt32)InputType.KEYBOARD;
            up.Data.Keyboard = new KEYBDINPUT();
            up.Data.Keyboard.Vk = (UInt16)keyCode;
            up.Data.Keyboard.Scan = (ushort)MapVirtualKeyEx((UInt16)keyCode, MapVirtualKeyMapTypes.MAPVK_VK_TO_VSC_EX, IntPtr.Zero);
            up.Data.Keyboard.Flags = (UInt32)KeyboardFlag.KEYUP;
            up.Data.Keyboard.Time = 0;
            up.Data.Keyboard.ExtraInfo = IntPtr.Zero;

            INPUT[] inputList = new INPUT[1];
            inputList[0] = up;

            var numberOfSuccessfulSimulatedInputs = SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT)));
            if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key up simulation for {0} was not successful.", keyCode));
        }
예제 #33
0
 /// <summary>
 /// Performs a modified keystroke where there are multiple modifiers and one key like CTRL-ALT-C where CTRL and ALT are the modifierKeys and C is the key.
 /// The flow is Modifiers KEYDOWN in order, Key PRESS, Modifiers KEYUP in reverse order.
 /// </summary>
 /// <param name="modifierKeyCodes">The list of modifier keys</param>
 /// <param name="keyCode">The key to simulate</param>
 public static void SimulateModifiedKeyStroke(IEnumerable<VirtualKey> modifierKeyCodes, VirtualKey keyCode)
 {
     if (modifierKeyCodes != null) modifierKeyCodes.ToList().ForEach(x => SimulateKeyDown(x));
     SimulateKeyPress(keyCode);
     if (modifierKeyCodes != null) modifierKeyCodes.Reverse().ToList().ForEach(x => SimulateKeyUp(x));
 }
예제 #34
0
 public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifierFlags fsModifiers, VirtualKey vk);
예제 #35
0
        public static bool TryParseNode(Genero4glParser parser, out ConstructControlBlock node,
                                        IModuleResult containingModule,
                                        List <Func <PrepareStatement, bool> > prepStatementBinders,
                                        Func <ReturnStatement, ParserResult> returnStatementBinder   = null,
                                        Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null,
                                        List <TokenKind> validExitKeywords = null,
                                        IEnumerable <ContextStatementFactory> contextStatementFactories = null,
                                        HashSet <TokenKind> endKeywords = null)
        {
            node = new ConstructControlBlock();
            bool result = true;

            node.StartIndex    = parser.Token.Span.Start;
            node.FieldSpecList = new List <FglNameExpression>();
            node.KeyNameList   = new List <VirtualKey>();

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.Ampersand:
            {
                // handle include file
                PreprocessorNode preNode;
                PreprocessorNode.TryParseNode(parser, out preNode);
                node.StartIndex = -1;
                break;
            }

            case TokenKind.BeforeKeyword:
            case TokenKind.AfterKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.FieldKeyword))
                {
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Field;
                    // get the list of field specs
                    FglNameExpression fieldSpec;
                    while (FglNameExpression.TryParseNode(parser, out fieldSpec))
                    {
                        node.FieldSpecList.Add(fieldSpec);
                        if (!parser.PeekToken(TokenKind.Comma))
                        {
                            break;
                        }
                        parser.NextToken();
                    }
                }
                else if (parser.PeekToken(TokenKind.ConstructKeyword))
                {
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Construct;
                }
                else
                {
                    parser.ReportSyntaxError("Unexpected token found in construct control block.");
                    result = false;
                }
                break;
            }

            case TokenKind.OnKeyword:
            {
                parser.NextToken();
                switch (parser.PeekToken().Kind)
                {
                case TokenKind.IdleKeyword:
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Idle;
                    // get the idle seconds
                    ExpressionNode idleExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out idleExpr))
                    {
                        node.IdleSeconds = idleExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid idle-seconds found in construct statement.");
                    }
                    break;

                case TokenKind.ActionKeyword:
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Action;
                    // get the action name
                    FglNameExpression actionName;
                    if (FglNameExpression.TryParseNode(parser, out actionName))
                    {
                        node.ActionName = actionName;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid action-name found in construct statement.");
                    }
                    if (parser.PeekToken(TokenKind.InfieldKeyword))
                    {
                        parser.NextToken();
                        // get the field-spec
                        if (FglNameExpression.TryParseNode(parser, out actionName))
                        {
                            node.ActionField = actionName;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid field-spec found in construct statement.");
                        }
                    }
                    break;

                case TokenKind.KeyKeyword:
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Key;
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        // get the list of key names
                        VirtualKey keyName;
                        while (VirtualKey.TryGetKey(parser, out keyName))
                        {
                            node.KeyNameList.Add(keyName);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in construct control block.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in construct control block.");
                    }
                    break;

                default:
                    parser.ReportSyntaxError("Unexpected token found in input control block.");
                    //result = false;
                    break;
                }
                break;
            }

            default:
                result = false;
                break;
            }

            if (result && node.StartIndex >= 0)
            {
                // get the dialog statements
                FglStatement inputStmt;
                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (ConstructDialogStatementFactory.TryGetStatement(parser, out inputStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                                       limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords) && inputStmt != null)
                {
                    node.Children.Add(inputStmt.StartIndex, inputStmt);
                }
                prepStatementBinders.RemoveAt(0);

                if (node.Type == ConstructControlBlockType.None && node.Children.Count == 0)
                {
                    result = false;
                }
            }

            return(result);
        }
예제 #36
0
 public KeyPress(VirtualKey virtualKey, ShiftState shiftState)
 {
     VirtualKey = virtualKey;
     ShiftState = shiftState;
 }
예제 #37
0
 public static byte ToScanCode(this VirtualKey virtualKey)
 {
     return((byte)User32.MapVirtualKeyEx((uint)virtualKey, (uint)MapVirtualKeyMapTypes.VirtualKey2ScanCode, KeyboardManager.GetKeyboardLayout()));
 }
예제 #38
0
 internal HotKeyBind(Shortcut shortcut, VirtualKey key, HotKeyModifiers modifiers)
 {
     Shortcut  = shortcut;
     Key       = key;
     Modifiers = modifiers;
 }
예제 #39
0
 public static KeyState GetKeyState(VirtualKey virtualKey)
 {
     return((KeyState)User32.GetKeyState((int)virtualKey));
 }
예제 #40
0
 private static bool IsExtendedKey(VirtualKey virtualKey)
 => (virtualKey >= VirtualKey.PageUp && virtualKey <= VirtualKey.Down) ||
 virtualKey == VirtualKey.Insert ||
 virtualKey == VirtualKey.Delete;
예제 #41
0
 public static bool IsKeyToggled(VirtualKey virtualKey)
 {
     return(GetKeyState(virtualKey).HasFlag(KeyState.Toggled));
 }
 public CoreVirtualKeyStates GetKeyState(VirtualKey vkey)
 {
     return(this.window.GetAsyncKeyState(vkey));
 }
예제 #43
0
 public static extern short GetKeyState(VirtualKey nVirtKey);
예제 #44
0
        public static bool TryParseNode(Genero4glParser parser, out DisplayControlBlock node, IModuleResult containingModule, bool allowNonControlBlocks,
                                        bool isArray,
                                        List <Func <PrepareStatement, bool> > prepStatementBinders,
                                        Func <ReturnStatement, ParserResult> returnStatementBinder   = null,
                                        Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null,
                                        List <TokenKind> validExitKeywords = null,
                                        IEnumerable <ContextStatementFactory> contextStatementFactories = null,
                                        HashSet <TokenKind> endKeywords = null)
        {
            node = new DisplayControlBlock();
            bool result = true;

            node.KeyNameList = new List <VirtualKey>();

            bool isDragAndDrop = false;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.Ampersand:
            {
                // handle include file
                PreprocessorNode preNode;
                PreprocessorNode.TryParseNode(parser, out preNode);
                node.StartIndex = -1;
                break;
            }

            case TokenKind.BeforeKeyword:
            case TokenKind.AfterKeyword:
            {
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                if (parser.PeekToken(TokenKind.DisplayKeyword))
                {
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Display;
                }
                else if (parser.PeekToken(TokenKind.RowKeyword))
                {
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Row;
                }
                else
                {
                    parser.ReportSyntaxError("Unexpected keyword found in display control block.");
                    result = false;
                }
                break;
            }

            case TokenKind.OnKeyword:
            {
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                switch (parser.PeekToken().Kind)
                {
                case TokenKind.IdleKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Idle;
                    // get the idle seconds
                    ExpressionNode idleExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out idleExpr))
                    {
                        node.IdleSeconds = idleExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid idle-seconds found in display array statement.");
                    }
                    break;

                case TokenKind.TimerKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Timer;
                    // get the timer seconds
                    ExpressionNode timerExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out timerExpr))
                    {
                        node.TimerSeconds = timerExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid timer-seconds found in display array statement.");
                    }
                    break;

                case TokenKind.ActionKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Action;
                    // get the action name
                    FglNameExpression actionName;
                    if (FglNameExpression.TryParseNode(parser, out actionName))
                    {
                        node.ActionName = actionName;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid action-name found in display array statement.");
                    }
                    GetActionAttributesDisplayArray(parser);
                    break;

                case TokenKind.KeyKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Key;
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        // get the list of key names
                        VirtualKey keyName;
                        while (VirtualKey.TryGetKey(parser, out keyName))
                        {
                            node.KeyNameList.Add(keyName);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in display array block.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in display array block.");
                    }
                    break;

                case TokenKind.AppendKeyword:
                    node.Type = DisplayControlBlockType.Append;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.InsertKeyword:
                    node.Type = DisplayControlBlockType.Insert;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.UpdateKeyword:
                    node.Type = DisplayControlBlockType.Update;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.DeleteKeyword:
                    node.Type = DisplayControlBlockType.Delete;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.ExpandKeyword:
                    node.Type = DisplayControlBlockType.Expand;
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        FglNameExpression rowInd;
                        if (FglNameExpression.TryParseNode(parser, out rowInd))
                        {
                            node.RowIndex = rowInd;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid row-index found in display array statement.");
                        }

                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in display array statement.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in display array statement.");
                    }
                    break;

                case TokenKind.CollapseKeyword:
                    node.Type = DisplayControlBlockType.Collapse;
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        FglNameExpression rowInd1;
                        if (FglNameExpression.TryParseNode(parser, out rowInd1))
                        {
                            node.RowIndex = rowInd1;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid row-index found in display array statement.");
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in display array statement.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in display array statement.");
                    }
                    break;

                case TokenKind.Drag_EnterKeyword:
                    node.Type = DisplayControlBlockType.DragEnter;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.Drag_FinishKeyword:
                case TokenKind.Drag_FinishedKeyword:
                    node.Type = DisplayControlBlockType.DragFinish;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.Drag_OverKeyword:
                    node.Type = DisplayControlBlockType.DragOver;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.Drag_StartKeyword:
                    node.Type = DisplayControlBlockType.DragStart;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.DropKeyword:
                    node.Type = DisplayControlBlockType.Drop;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                default:
                    parser.ReportSyntaxError("Unexpected token found in input control block.");
                    result = false;
                    break;
                }
                break;
            }

            default:
                if (!allowNonControlBlocks)
                {
                    result = false;
                }
                else
                {
                    node.StartIndex = parser.Token.Span.Start;
                }
                break;
            }

            if (result && node.StartIndex >= 0)
            {
                node.DecoratorEnd = parser.Token.Span.End;
                if (isDragAndDrop)
                {
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        FglNameExpression keyName;
                        if (FglNameExpression.TryParseNode(parser, out keyName))
                        {
                            node.DragAndDropObject = keyName;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid drag-and-drop object name found in display array statement.");
                        }

                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in input control block.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in input control block.");
                    }
                }

                // get the dialog statements
                FglStatement dispStmt;
                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (DisplayStatementFactory.TryGetStatement(parser, out dispStmt, isArray, containingModule, prepStatementBinders, returnStatementBinder,
                                                               limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords) && dispStmt != null)
                {
                    node.Children.Add(dispStmt.StartIndex, dispStmt);
                    node.EndIndex = dispStmt.EndIndex;
                }
                prepStatementBinders.RemoveAt(0);

                if (node.Type == DisplayControlBlockType.None && node.Children.Count == 0)
                {
                    result = false;
                }
            }

            return(result);
        }
예제 #45
0
        /// <summary>
        /// Provides different key shortcuts
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown(VirtualKey key)
        {
            switch (key)
            {
            case VirtualKey.Left:
                NavigateBack.ExecuteWhen();
                break;

            case VirtualKey.Right:
                NavigateForward.ExecuteWhen();
                break;

            case VirtualKey.Back:
                NavigateBack.ExecuteWhen();
                break;

            case VirtualKey.F5:
                Refresh();
                break;

            case VirtualKey.F2:
                RenameStorageItemSelectedAsync();
                break;

            case VirtualKey.Delete:
                DeleteStorageItemSelected();
                break;
            }


            var ctrlDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);

            if (!ctrlDown)
            {
                return;
            }

            switch (key)
            {
            case VirtualKey.R:
                Refresh();
                break;

            case VirtualKey.C:
                CopyStorageItemSelected();
                break;

            case VirtualKey.X:
                CutStorageItemSelected();
                break;

            case VirtualKey.V:
                PasteStorageItemSelected();
                break;

            case VirtualKey.A:
                if (SelectedItems.Count == FileSystemElements.Count)
                {
                    SelectedItems.Clear();
                }
                else
                {
                    for (int i = 0; i < FileSystemElements.Count; i++)
                    {
                        if (!SelectedItems.Contains(FileSystemElements[i]))
                        {
                            SelectedItems.Add(FileSystemElements[i]);
                        }
                    }
                }

                break;
            }
        }
예제 #46
0
 protected KeyPress KeyPress(VirtualKey virtualKey, ShiftState shiftState)
 => new KeyPress(virtualKey, shiftState);
예제 #47
0
 protected KeyPress Shift(VirtualKey virtualKey)
 => new KeyPress(virtualKey, ShiftState.Shift);
예제 #48
0
 public static void AddKeyState(VirtualKey virtualKey, KeyState state)
 {
     SetKeyState(virtualKey, GetKeyState(virtualKey) | state);
 }
예제 #49
0
 public static extern uint MapVirtualKey(VirtualKey uCode, VirtualKeyMapType uMapType);
예제 #50
0
 public static void RemoveKeyState(VirtualKey virtualKey, KeyState state)
 {
     SetKeyState(virtualKey, GetKeyState(virtualKey) & ~state);
 }
예제 #51
0
 public static extern KeyState GetKeyState(VirtualKey vKey);
예제 #52
0
 public static void KeyUp(VirtualKey virtualKey)
 {
     User32.keybd_event((byte)virtualKey, virtualKey.ToScanCode(), (uint)(KeyboardEventFlag.ExtendedKey | KeyboardEventFlag.KeyUp), UIntPtr.Zero);
 }
예제 #53
0
        /// <summary>
        /// Calls the Win32 SendInput method to simulate a Key UP.
        /// </summary>
        /// <param name="keyCode">The VirtualKeyCode to lift up</param>
        public static void SimulateKeyUp(VirtualKey keyCode, ushort scancode)
        {
            var up = new INPUT();
            up.Type = (UInt32)InputType.KEYBOARD;
            up.Data.Keyboard = new KEYBDINPUT();
            up.Data.Keyboard.Vk = (UInt16)keyCode;
            up.Data.Keyboard.Scan = scancode;
            up.Data.Keyboard.Flags = (UInt32)KeyboardFlag.KEYUP;
            if (((scancode >> 8) == 0xe0) || ((scancode >> 8) == 0xe1))
                up.Data.Keyboard.Flags |= (UInt32)KeyboardFlag.EXTENDEDKEY;
            up.Data.Keyboard.Time = 0;
            up.Data.Keyboard.ExtraInfo = IntPtr.Zero;

            INPUT[] inputList = new INPUT[1];
            inputList[0] = up;

            var numberOfSuccessfulSimulatedInputs = SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT)));
            if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key up simulation for {0} was not successful.", keyCode));
        }
예제 #54
0
        /// <summary>
        /// Exposed for testing purposes only.
        /// </summary>
        /// <returns>True if the key is a valid character in the numeric context.</returns>
        internal bool PreviewKeyDown(VirtualKey key)
        {
            if (KeyboardHelper.IsModifierKeyDown(VirtualKey.Control))
            {
                // allow CTRL+[xxx] based operations
                return(true);
            }

            if (IsNumericKey(key))
            {
                if (KeyboardHelper.IsModifierKeyDown(VirtualKey.Shift) && (key >= VirtualKey.NumberPad0 && key <= VirtualKey.NumberPad9))
                {
                    // handle SHIFT + Number (for example : with AZERTY keyboard layout : SHIFT + Number = Number).
                    // do not handle input when the SHIFT key is down/locked.
                    return(false);
                }

                // allow base handling of numeric-related chars
                return(true);
            }

            if (IsNegativeSign(key))
            {
                this.isNegative = true;
                this.ValidateText();
            }
            else if (this.IsDecimalSeparator(key))
            {
                this.isDecimal = this.AcceptsDecimalSeparator;

                if (this.isDecimal)
                {
                    var selectionStartCache = this.textBox.SelectionStart;

                    this.textBox.Text = this.textBox.Text.Remove(this.textBox.SelectionStart, this.textBox.SelectionLength);

                    this.textBox.SelectionStart = selectionStartCache;

                    if (this.textBox.Text == string.Empty)
                    {
                        this.SetText("0");
                    }
                    else if (this.textBox.Text == "-")
                    {
                        this.SetText("-0");
                    }
                }

                this.ValidateText();
            }
            else
            {
                switch (key)
                {
                // Allowed key strokes
                case VirtualKey.Left:
                case VirtualKey.Right:
                case VirtualKey.Back:
                case VirtualKey.Delete:
                case VirtualKey.Home:
                case VirtualKey.End:
                case VirtualKey.Tab:
                    return(true);

                case VirtualKey.Enter:
                    this.KillTextBoxFocus();
                    break;

                case VirtualKey.Down:
                    this.DecrementValue(this.SmallChange);
                    break;

                case VirtualKey.Up:
                    this.IncrementValue(this.SmallChange);
                    break;

                case VirtualKey.PageDown:
                    this.DecrementValue(this.LargeChange);
                    break;

                case VirtualKey.PageUp:
                    this.IncrementValue(this.LargeChange);
                    break;
                }

                if (key == VirtualKey.Down || key == VirtualKey.Up ||
                    key == VirtualKey.PageDown || key == VirtualKey.PageUp)
                {
                    this.UpdateTextBoxText();
                }
            }

            return(false);
        }
예제 #55
0
 /// <summary>
 /// Performs a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key.
 /// The flow is Modifier KEYDOWN, Key PRESS, Modifier KEYUP.
 /// </summary>
 /// <param name="modifierKeyCode">The modifier key</param>
 /// <param name="keyCode">The key to simulate</param>
 public static void SimulateModifiedKeyStroke(VirtualKey modifierKeyCode, VirtualKey keyCode)
 {
     SimulateKeyDown(modifierKeyCode);
     SimulateKeyPress(keyCode);
     SimulateKeyUp(modifierKeyCode);
 }
예제 #56
0
파일: User32API.cs 프로젝트: Joker0727/Ant
 public static extern void Keybd_event(VirtualKey bVk, byte bScan, KeyEvent dwFlags, uint dwExtraInfo);
예제 #57
0
 /// <summary>
 /// Performs a modified keystroke where there is one modifier and multiple keys like CTRL-K-C where CTRL is the modifierKey and K and C are the keys.
 /// The flow is Modifier KEYDOWN, Keys PRESS in order, Modifier KEYUP.
 /// </summary>
 /// <param name="modifierKey">The modifier key</param>
 /// <param name="keyCodes">The list of keys to simulate</param>
 public static void SimulateModifiedKeyStroke(VirtualKey modifierKey, IEnumerable<VirtualKey> keyCodes)
 {
     SimulateKeyDown(modifierKey);
     if (keyCodes != null) keyCodes.ToList().ForEach(x => SimulateKeyPress(x));
     SimulateKeyUp(modifierKey);
 }
예제 #58
0
파일: User32API.cs 프로젝트: Joker0727/Ant
 public static extern int ToAsciiEx(VirtualKey uVirtKey, uint uScanCode, IntPtr lpKeyState, out ushort lpChar, uint uFlags, IntPtr dwhkl);
예제 #59
0
 /// <summary>
 /// Determines whether the toggling key is toggled on (in-effect) or not by calling the GetKeyState function.  (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
 /// </summary>
 /// <param name="keyCode">The <see cref="VirtualKey"/> for the key.</param>
 /// <returns>
 /// 	<c>true</c> if the toggling key is toggled on (in-effect); otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. 
 /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. 
 /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. 
 /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. 
 /// VK_LSHIFT
 /// VK_RSHIFT
 /// VK_LCONTROL
 /// VK_RCONTROL
 /// VK_LMENU
 /// VK_RMENU
 /// 
 /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. 
 /// </remarks>
 public static bool IsTogglingKeyInEffect(VirtualKey keyCode)
 {
     Int16 result = GetKeyState((UInt16)keyCode);
     //if (result == -127 || result == 1)
     //    return true;
     //else
     //    return false;
     return (result & 0x01) != 0x00;
 }
 /// <summary>
 /// Add a ActionKey CallbackFunction binding to the flag ListView.
 /// </summary>
 /// <param name="key">The action key that raises the callback.</param>
 /// <param name="callback">The callback function with the action that should be called.</param>
 /// <param name="modifierKeys">Required state of the modifier keys to get the callback function called.</param>
 /// <param name="once">Flag to determine if the callback function should only be called once.</param>
 public void AddActionKey(VirtualKey key, ActionKeyHandler callback, ModifierKey[] modifierKeys = null, bool once = false)
 {
     tvModSelection.AddActionKey(key, callback, modifierKeys, once);
 }