/// <include file='Internal.xml' path='Docs/KeyboardHook/GetKeyboardReading/*'/>
        protected KeyboardHookEventArgs GetKeyboardReading(IntPtr lparam)
        {
            ThrowIfDisposed();

            int vkCode;
            int alt;
            int ctrl;
            int shift;
            int capsLock;

            if (!InternalGetKeyboardReading(lparam, out vkCode, out alt, out ctrl, out shift, out capsLock))
            {
                throw new ManagedHooksException("Failed to access keyboard settings.");
            }

            VirtualKeys vk = (VirtualKeys)vkCode;

            System.Windows.Forms.Keys key = ConvertKeyCode(vk);

            if ((int)key == -1)
            {
                return(null);
            }

            return(new KeyboardHookEventArgs(key, alt == 1, ctrl == 1, shift == 1, capsLock == 1));
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override void UnregisterHotKey(VirtualKeys key, Modifiers modifiers)
        {
            // remove no repeat before adding to list to avoid getting different hash
            modifiers = (Modifiers)((uint)modifiers & 0xF);

            KeyModifierCombination combination = new KeyModifierCombination(key, modifiers);

            if (!HotKeys.ContainsKey(combination))
            {
                String error = $"Failed to unregister hotKey : HotKey \"{key}+{modifiers}\" is not registered";
                Logger.Warn(error);
                throw new HotKeyException(error);
            }

            try
            {
                HotKey tmpHotKey = HotKeys[combination];
                tmpHotKey.UnregisterHotKey();
                HotKeysId.Remove(tmpHotKey.Id);
                HotKeys.Remove(combination);
            }
            catch (HotKeyException e)
            {
                Logger.Warn("Failed to unregister hotKey : {0}", e.Message);
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>Is called when a key is pressed.</summary>
        /// <param name="key">The key.</param>
        internal override void KeyDown(VirtualKeys key)
        {
            switch (key)
            {
            case VirtualKeys.B1:
                // --- reset the system ---
                if ((this.State == States.Brake | this.State == States.Service | this.State == States.Emergency) & this.Train.Handles.Reverser == 0 & this.Train.Handles.PowerNotch == 0 & this.Train.Handles.BrakeNotch >= this.Train.Specs.BrakeNotches)
                {
                    foreach (Pattern pattern in this.Patterns)
                    {
                        if (Math.Abs(this.Train.State.Speed.MetersPerSecond) >= pattern.WarningPattern)
                        {
                            pattern.Clear();
                        }
                    }
                    this.State = States.Normal;
                    this.Train.Sounds.AtsPBell.Play();
                }
                break;

            case VirtualKeys.B2:
                // --- brake release ---
                if ((this.State == States.Normal | this.State == States.Pattern) & !BrakeRelease & DurationOfBrakeRelease > 0.0)
                {
                    BrakeRelease          = true;
                    BrakeReleaseCountdown = DurationOfBrakeRelease;
                    this.Train.Sounds.AtsPBell.Play();
                }
                break;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Create a new accelerator from the given accelerator key and virtual key combination.
        /// </summary>
        /// <param name="acceleratorKey">
        ///     The accelerator key (Ctrl, Alt, or Shift). Can be combined with | to form more complicated keystrokes
        ///     such as Ctrl + Alt + Space.
        /// </param>
        /// <param name="virtualKey">
        ///     The virtual key code (may not be Ctrl, Alt, or Shift).
        /// </param>
        public Accelerator(AcceleratorKeys acceleratorKey, VirtualKeys virtualKey)
        {
            AcceleratorKey = acceleratorKey;
            VirtualKey = virtualKey;
            Command = Macros.MAKEWORD((byte)AcceleratorKey, (byte)VirtualKey);

            lock(builderLock) {

                //create a string representation of this accelerators keystroke such as "CONTROL + SPACE"
                foreach(var key in acceleratorKeys.Keys) {
                    if(AcceleratorKey.Any(key)) {
                        stringBuilder.Append(acceleratorKeys[key])
                                     .Append(SEPARATOR);
                    }
                }
                stringBuilder.Append(virtualKeys[VirtualKey]);
                str = stringBuilder.ToString();
                stringBuilder.Clear();
            }

            Accel = new ACCEL() {
                fVirt = (byte)(AcceleratorKey | (AcceleratorKeys)VIRTKEY),
                key = (ushort)VirtualKey,
                cmd = Command
            };
        }
Exemplo n.º 5
0
    public async Task <object> releaseKey(String key)
    {
        VirtualKeys keyNum = (VirtualKeys)Enum.Parse(typeof(VirtualKeys), key, true);

        keybd_event((byte)keyNum, 0, KEYEVENTF_KEYUP, UIntPtr.Zero);
        return(0);
    }
Exemplo n.º 6
0
    public async Task <object> holdKey(String key)
    {
        VirtualKeys keyNum = (VirtualKeys)Enum.Parse(typeof(VirtualKeys), key, true);

        keybd_event((byte)keyNum, 0, 0, UIntPtr.Zero);
        return(0);
    }
Exemplo n.º 7
0
 internal void KeyDown(VirtualKeys key)
 {
     foreach (Device device in devices.Values)
     {
         device.KeyDown(key);
     }
 }
Exemplo n.º 8
0
 static void sKeyUp(VirtualKeys key)
 {
     if (!GUCMenu.KeyUpUpdateMenus(key) && Active != null)
     {
         Active.KeyUp(key);
     }
 }
Exemplo n.º 9
0
        private void aim_key_Click(object sender, EventArgs e)
        {
            var key = PromptKey();

            aim_key.Text = key.ToString();
            _aim_key     = key;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Sends a virtual key.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="KeyUp"></param>
        /// <param name="inputType"></param>
        public static void SendKey(VirtualKeys key, bool KeyUp, InputType inputType)
        {
            uint flagtosend;

            if (KeyUp)
            {
                flagtosend = (uint)(KeyEventF.KeyUp);
            }
            else
            {
                flagtosend = (uint)(KeyEventF.KeyDown);
            }

            Input[] inputs =
            {
                new Input
                {
                    type = (int)inputType,
                    u    = new InputUnion
                    {
                        ki = new KeyboardInput
                        {
                            wVk         = (ushort)key,
                            wScan       = 0,
                            dwFlags     = flagtosend,
                            dwExtraInfo = GetMessageExtraInfo()
                        }
                    }
                }
            };
            SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input)));
        }
Exemplo n.º 11
0
 /// <summary>Is called when a virtual key is pressed.</summary>
 public void KeyDown(VirtualKeys key)
 {
     DVS.KeyDown(key);
     PanelManager.KeyDown(key, Panel);
     ATSSoundManager.PlayOnce(key);
     ATSSoundManager.PlayLoop(key);
 }
Exemplo n.º 12
0
        private void HookEx_Events(object sender, WindowsHookExEventArgs e)
        {
            if (KeyChange == null)
            {
                return;
            }
            KeyboardLLHookStruct @struct   = (KeyboardLLHookStruct)Marshal.PtrToStructure((IntPtr)e.lParam, typeof(KeyboardLLHookStruct));
            PressType            pressType = PressType.None;
            VirtualKeys          vk        = (VirtualKeys)@struct.VirtualKeyCode;
            KeyboardState        state     = KeyboardState.FromCurrentState();
            char?inputChar = null;

            if (e.wParam.ToInt64() == WM.KEYDOWN || e.wParam.ToInt64() == WM.SYSKEYDOWN)
            {
                pressType = PressType.KeyDown;
            }
            else if (e.wParam.ToInt64() == WM.KEYUP || e.wParam.ToInt64() == WM.SYSKEYUP)
            {
                pressType = PressType.KeyUp;
            }
            // Get Press Char
            char?PressKey = null;

            byte[] inBuffer = new byte[2];
            if (User32.ToAscii(@struct.VirtualKeyCode,
                               @struct.ScanCode,
                               state.Bytes,
                               inBuffer,
                               @struct.Flags) == 1)
            {
                char ch = (char)inBuffer[0];
                if (!char.IsControl(ch))
                {
                    PressKey = ch;
                    if ((state.CapsLockToggled ^ state.ShiftPressed) && char.IsLetter(ch))
                    {
                        PressKey = char.ToUpper(ch);
                    }
                    inputChar = PressKey;
                }
            }
            var args = new KeyChangeEventArgs()
            {
                Handled       = false,
                PressType     = pressType,
                Key           = vk,
                KeyboardState = state,
                InputChar     = inputChar,
            };

            foreach (var action in KeyChange.GetInvocationList().Reverse())
            {
                action.DynamicInvoke(this, args);
                if (args.Handled)
                {
                    e.Handled = true;
                    return;
                }
            }
        }
Exemplo n.º 13
0
        private void KeyboardInputSource_KeyboardInput(object sender, RawKeyboardInputEventArgs e)
        {
            // only evaluate this event if it is actually intended for this device
            //TODO: add some sort of conditional event invocation before this
            if (e.Header.hDevice != DeviceHandle)
            {
                return;
            }

            VirtualKeys key = (VirtualKeys)e.Data.VirtualKey;

            switch ((WM)e.Data.Message)
            {
            case WM.KEYDOWN:
            {
                KeyDown?.Invoke(this, new KeyInputEventArgs(key));
                break;
            }

            case WM.KEYUP:
            {
                KeyUp?.Invoke(this, new KeyInputEventArgs(key));
                break;
            }

            case WM.SYSKEYDOWN:
            {
                //TODO: syskeydown
                break;
            }
            }
        }
Exemplo n.º 14
0
        protected override void HookCallback(int code, UIntPtr wparam, IntPtr lparam)
        {
            if (KeyboardEvent == null)
            {
                return;
            }

            int            vkCode = 0;
            KeyboardEvents kEvent = (KeyboardEvents)wparam.ToUInt32();

            if (kEvent != KeyboardEvents.KeyDown &&
                kEvent != KeyboardEvents.KeyUp &&
                kEvent != KeyboardEvents.SystemKeyDown &&
                kEvent != KeyboardEvents.SystemKeyUp)
            {
                return;
            }

            GetKeyboardReading(wparam, lparam, ref vkCode);
            VirtualKeys vk = (VirtualKeys)vkCode;

            Keys key;

            if (keyMap.TryGetValue(vk, out key))
            {
                KeyboardEvent(kEvent, key);
            }
        }
Exemplo n.º 15
0
        /// <summary>Is called when a key is pressed.</summary>
        /// <param name="key">The key.</param>
        internal override void KeyDown(VirtualKeys key)
        {
            switch (key)
            {
            case VirtualKeys.C1:
                // --- switch to ats ---
                if (this.State == States.Normal | this.State == States.Service | this.State == States.Emergency)
                {
                    if (this.Train.AtsSx != null | this.Train.AtsP != null)
                    {
                        this.State = States.Ats;
                        this.Train.Sounds.ToAts.Play();
                    }
                }
                break;

            case VirtualKeys.C2:
                // --- switch to atc ---
                if (this.State == States.Ats)
                {
                    this.State = States.Normal;
                    this.Train.Sounds.ToAtc.Play();
                }
                break;
            }
        }
Exemplo n.º 16
0
        internal static void KeyDown(VirtualKeys key)
        {
            if (key == rsettimerkey)
            {
                ResetTimer();
            }
            else
            {
                switch (key)
                {
                case VirtualKeys.LeftDoors:
                    if (ResetOnDoorMove)
                    {
                        ScheduleResetTimer = true;
                    }
                    break;

                case VirtualKeys.RightDoors:
                    if (ResetOnDoorMove)
                    {
                        ScheduleResetTimer = true;
                    }
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 17
0
        protected override void KeyPress(VirtualKeys key, bool hold)
        {
            if (hold)
            {
                return;
            }

            if (key == VirtualKeys.Escape || key == VirtualKeys.Tab)
            {
                Close();
            }
            else if (key == VirtualKeys.Return || key == VirtualKeys.Control || key == VirtualKeys.Menu)
            {
                int amount = Convert.ToInt32(tb.Input.ToString().Length > 0 ? tb.Input : "0");
                if (amount != 0)
                {
                    amount = amount > maxAmount ? maxAmount : amount;
                    NPCInst.Requests.DropItem(player, item, amount);
                }
                Close();
            }
            else
            {
                tb.KeyPressed(key);
            }
        }
 internal KeyDownEvent(Script script, VirtualKeys key)
 {
     this.Script = script;
     this.Conditions = new List<Condition>();
     this.Actions = new List<Action>();
     this.Key = key;
 }
Exemplo n.º 19
0
 // Public methods
 /// <summary>
 /// Sends a WM_KEYDOWN command to the assigned process.
 /// </summary>
 /// <param name="key">VirtualKey which will be the keystroke.</param>
 public async Task SendKeystroke(VirtualKeys key)
 {
     // Send the character keystroke to the process
     Win32.PostMessage(_settings.Process.MainWindowHandle, Win32.WM_KEYDOWN, (int)key, 0);
     // Delay between keystrokes, ensures that any next input is after this one and not before (in case this method is called in a loop)
     await Task.Delay(_settings.DelayBetweenKeyPresses);
 }
Exemplo n.º 20
0
        /// <summary>
        /// ATSキーが押されたときに呼び出される関数
        /// </summary>
        /// <param name="key">ATSキー</param>
        internal override void KeyDown(VirtualKeys key)
        {
            switch (key)
            {
            case VirtualKeys.I:  // 手元灯
                LightSwDown();
                break;

            case VirtualKeys.L:  // LCD表示切り替え
                LcdSwDown();
                break;

            default:
                break;
            }

            // 修飾キーの更新
            if (modifier_key_ == null)
            {
                modifier_key_ = key;
            }

            // カスタムスイッチ
            for (int i = 0; i < LoadSwitch.ALL_SWITCH; i++)
            {
                if (SwitchCheck(0, key, LoadSwitch.switch_config_[i]))
                {
                    SwitchRight(i, ref switch_[i], LoadSwitch.switch_config_[i]);
                }
                else if (SwitchCheck(1, key, LoadSwitch.switch_config_[i]))
                {
                    SwitchLeft(i, ref switch_[i], LoadSwitch.switch_config_[i]);
                }
            }
        }
Exemplo n.º 21
0
 internal override void KeyUp(VirtualKeys key)
 {
     if (key == Train.CurrentKeyConfiguration.AWSKey)
     {
         awsKeyPressed = false;
     }
 }
Exemplo n.º 22
0
        public static Modifiers ToModifiers(this VirtualKeys vk)
        {
            switch (vk)
            {
            case VirtualKeys.Control:
            case VirtualKeys.LeftControl:
            case VirtualKeys.RightControl:
                return(Modifiers.CONTROL);

            case VirtualKeys.Shift:
            case VirtualKeys.LeftShift:
            case VirtualKeys.RightShift:
                return(Modifiers.SHIFT);

            case VirtualKeys.Menu:
            case VirtualKeys.LeftMenu:
            case VirtualKeys.RightMenu:
                return(Modifiers.ALT);

            case VirtualKeys.LeftWindows:
            case VirtualKeys.RightWindows:
                return(Modifiers.WIN);

            default:
                return(Modifiers.None);
            }
        }
Exemplo n.º 23
0
 public static bool IsModifiersExactKeyPress(this VirtualKeys vk)
 {
     return(vk == VirtualKeys.LeftControl || vk == VirtualKeys.RightControl ||
            vk == VirtualKeys.LeftShift || vk == VirtualKeys.RightShift ||
            vk == VirtualKeys.LeftMenu || vk == VirtualKeys.RightMenu ||
            vk == VirtualKeys.LeftWindows || vk == VirtualKeys.RightWindows);
 }
Exemplo n.º 24
0
			internal void SendWmKey(VirtualKeys key, IntPtr lParam)
			{
				XplatUI.SendMessage(owner.Handle, Msg.WM_KEYDOWN, (IntPtr)key, lParam);

				if (owner.IsHandleCreated) // The previous line could have caused disposing the control (esc, enter, ...)
					XplatUI.SendMessage(owner.Handle, Msg.WM_KEYUP, (IntPtr)key, lParam);
			}
Exemplo n.º 25
0
        public void KeyPressed(VirtualKeys key)
        {
            switch (key)
            {
            case VirtualKeys.Left:
                rotation -= 8;
                break;

            case VirtualKeys.Right:
                rotation += 8;
                break;

            case VirtualKeys.Add:
                distance -= 8;
                break;

            case VirtualKeys.Subtract:
                distance += 8;
                break;

            default:
                return;
            }

            UpdateOrientation();
        }
Exemplo n.º 26
0
        public static int onKeyboardAction(int nCode, int wParam, IntPtr lParam)
        {
            that.keyClickCounter = (that.keyClickCounter + 1) & (0xFFFF);

            if (!that.mouseOff)
            {
                // disable warning on variable not used.  These definition are present mostly
                // for information and possible future use.
#pragma warning disable 219
                const int MOUSEEVENTF_LEFTDOWN  = 0x02;
                const int MOUSEEVENTF_LEFTUP    = 0x04;
                const int MOUSEEVENTF_RIGHTDOWN = 0x08;
                const int MOUSEEVENTF_RIGHTUP   = 0x10;
#pragma warning restore 219

                KBDLLHOOKSTRUCT kbData = new KBDLLHOOKSTRUCT();
                Marshal.PtrToStructure(lParam, kbData);
                VirtualKeys vkCode       = (VirtualKeys)kbData.vkCode;
                long        currentTicks = DateTime.Now.Ticks;
                int         indexKey     = Array.BinarySearch(ignoreKeys, vkCode);
                if (indexKey < 0)
                {
                    that.mouseOff            = true;
                    that.mouseMoveStartTicks = 0L;
                }
            }

            int returnValue = (int)CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
            return(returnValue);
        }
Exemplo n.º 27
0
        /// <include file='ManagedHooks.xml' path='Docs/KeyboardHook/HookCallback/*'/>
        protected override void HookCallback(int code, UIntPtr wparam, IntPtr lparam)
        {
            if (KeyboardEvent == null)
            {
                return;
            }

            int            vkCode = 0;
            KeyboardEvents kEvent = (KeyboardEvents)wparam.ToUInt32();

            if (kEvent != KeyboardEvents.KeyDown &&
                kEvent != KeyboardEvents.KeyUp &&
                kEvent != KeyboardEvents.SystemKeyDown &&
                kEvent != KeyboardEvents.SystemKeyUp)
            {
                return;
            }

            GetKeyboardReading(wparam, lparam, ref vkCode);
            VirtualKeys vk = (VirtualKeys)vkCode;

            System.Windows.Forms.Keys key = ConvertKeyCode(vk);

            if (key == System.Windows.Forms.Keys.Attn)
            {
                return;
            }

            KeyboardEvent(kEvent, key);
        }
Exemplo n.º 28
0
        public void KeyPressed(VirtualKeys key)
        {
            if (key == VirtualKeys.Left)
            {
                cursor--;
                if (cursor < 0)
                {
                    cursor = choices.Count - 1;
                }
            }
            else if (key == VirtualKeys.Right)
            {
                cursor++;
                if (cursor >= choices.Count)
                {
                    cursor = 0;
                }
            }
            else
            {
                return;
            }

            UpdateChoiceText();
            if (OnChange != null)
            {
                OnChange();
            }
        }
Exemplo n.º 29
0
        protected override void KeyPress(VirtualKeys key, bool hold)
        {
            long now = GameTime.Ticks;

            switch (key)
            {
            case VirtualKeys.Return:
                if (!hold)
                {
                    items[cursor].OnActivate?.Invoke();
                    PlaySound(sndSelect);
                }
                break;

            case VirtualKeys.Escape:
                if (!hold)
                {
                    this.Close();
                    OnEscape?.Invoke();
                    PlaySound(sndEscape);
                }
                break;

            default:
                if (CurrentItem is InputReceiver rec)
                {
                    rec.KeyPressed(key);
                }
                break;
            }
        }
Exemplo n.º 30
0
 internal static bool IsKeyLocked(VirtualKeys key)
 {
                 #if DriverDebug || DriverDebugState
     Console.WriteLine("IsKeyLocked ({0}): Called, Result={1}", key, driver.IsKeyLocked(key));
                 #endif
     return(driver.IsKeyLocked(key));
 }
Exemplo n.º 31
0
 /// <summary>Is called when a key is released.</summary>
 /// <param name="key">The key.</param>
 internal void KeyUp(VirtualKeys key)
 {
     foreach (Device device in this.Devices)
     {
         device.KeyUp(key);
     }
 }
Exemplo n.º 32
0
        /// <summary>Is called when a key is pressed.</summary>
        /// <param name="key">The key.</param>
        internal override void KeyDown(VirtualKeys key)
        {
            switch (key)
            {
            case VirtualKeys.S:
                // --- acknowledge the alarm ---
                if (this.State == States.Alarm & this.Train.Handles.PowerNotch == 0 & this.Train.Handles.BrakeNotch >= this.Train.Specs.AtsNotch)
                {
                    this.State = States.Chime;
                }
                break;

            case VirtualKeys.A1:
                // --- stop the chime ---
                if (this.State == States.Chime)
                {
                    this.State = States.Normal;
                }
                break;

            case VirtualKeys.B1:
                // --- reset the system ---
                if (this.State == States.Emergency & this.Train.Handles.Reverser == 0 & this.Train.Handles.PowerNotch == 0 & this.Train.Handles.BrakeNotch == this.Train.Specs.BrakeNotches + 1)
                {
                    this.State = States.Chime;
                }
                break;
            }
        }
Exemplo n.º 33
0
 public KeyGesture( VirtualKeys key, ModifierKeys modifiers, string displayString ) {
     if ( displayString == null ) throw new ArgumentNullException( "displayString" );
     if ( !IsValid( key, modifiers ) )
         throw new InvalidOperationException( "KeyGesture is invalid" );
     this._modifiers = modifiers;
     this._key = key;
     this._displayString = displayString;
 }
Exemplo n.º 34
0
 private static int makeLp(VirtualKeys vk, int wmKey)
 {
     uint scanCode = User32.MapVirtualKey((uint)vk, 0);
     uint lParam = 0;
     lParam = (0x00000001 | (scanCode << 16));
     if (wmKey != WMsg.WM_KEYDOWN)
     {
         lParam |= 0xc0000000;
     }
     return (int)lParam;
 }
Exemplo n.º 35
0
 internal override void KeyDown(VirtualKeys key)
 {
     if (key == VirtualKeys.C1) //Mode Up
     {
         if ((int)train.trainModeSelected < train.trainModeCount - 1)
         {
             trainModeNew = train.trainModeSelected + 1;
         }
     }
     else if (key == VirtualKeys.C2) //Mode Down
     {
         if ((int)train.trainModeSelected > 0)
         {
             trainModeNew = train.trainModeSelected - 1;
         }
     }
 }
Exemplo n.º 36
0
        public static void RingPst(IntPtr hwnd, VirtualKeys vk, RingPstType keytype)
        {
            switch (keytype)
            {
                case RingPstType.press:
                    User32.PostMessageA((IntPtr)0x00d07aa, (uint)WMsg.WM_KEYDOWN, (int)vk, makeLp(vk, WMsg.WM_KEYDOWN));
                    User32.SendMessage((IntPtr)0x0004095e, (uint)WMsg.WM_KEYDOWN, vk, makeLp(vk, WMsg.WM_KEYDOWN));
                    System.Threading.Thread.Sleep(33);
                    User32.PostMessageA((IntPtr)0x00d07aa, (uint)WMsg.WM_KEYUP, (int)vk, makeLp(vk, WMsg.WM_KEYUP));
                    User32.SendMessage((IntPtr)0x0004095e, (uint)WMsg.WM_KEYUP, vk, makeLp(vk, WMsg.WM_KEYUP));
                    break;
                case RingPstType.down:
                    User32.PostMessageA(hwnd, (uint)WMsg.WM_KEYDOWN, (int)vk, makeLp(vk, WMsg.WM_KEYDOWN));
                    break;
                case RingPstType.up:
                    User32.PostMessageA(hwnd, (uint)WMsg.WM_KEYUP, (int)vk, makeLp(vk, WMsg.WM_KEYUP));
                    break;

            }
        }
Exemplo n.º 37
0
		/// <summary>Is called when a virtual key is pressed.</summary>
		/// <param name="key">The virtual key that was pressed.</param>
		public void KeyDown(VirtualKeys key) {
			// TODO: Your old KeyDown code goes here.
		}
Exemplo n.º 38
0
		/// <summary>Is called when a key is pressed.</summary>
		/// <param name="key">The key.</param>
		internal void KeyDown(VirtualKeys key) {
			if (key == VirtualKeys.D) {
				// --- enable safety systems ---
				if (this.AtsSx != null) {
					if (this.AtsSx.State == AtsSx.States.Disabled) {
						this.AtsSx.State = AtsSx.States.Suppressed;
					}
				}
				if (this.AtsP != null) {
					if (this.AtsP.State == AtsP.States.Disabled) {
						this.AtsP.State = AtsP.States.Suppressed;
					}
				}
				if (this.Atc != null) {
					if (this.Atc.State == Atc.States.Disabled) {
						this.Atc.State = Atc.States.Suppressed;
					}
				}
			} else if (key == VirtualKeys.E) {
				// --- disable safety systems ---
				if (this.AtsSx != null) {
					if (this.AtsSx.State != AtsSx.States.Disabled) {
						this.AtsSx.State = AtsSx.States.Disabled;
					}
				}
				if (this.AtsP != null) {
					if (this.AtsP.State != AtsP.States.Disabled) {
						this.AtsP.State = AtsP.States.Disabled;
					}
				}
				if (this.Atc != null) {
					if (this.Atc.State != Atc.States.Disabled) {
						this.Atc.State = Atc.States.Disabled;
					}
				}
			} else {
				// --- other functions ---
				foreach (Device device in this.Devices) {
					device.KeyDown(key);
				}
			}
		}
Exemplo n.º 39
0
		/// <summary>Is called when a key is released.</summary>
		/// <param name="key">The key.</param>
		internal void KeyUp(VirtualKeys key) {
			foreach (Device device in this.Devices) {
				device.KeyUp(key);
			}
		}
Exemplo n.º 40
0
		/// <summary>Is called when a key is released.</summary>
		/// <param name="key">The key.</param>
		internal override void KeyUp(VirtualKeys key) {
		}
Exemplo n.º 41
0
 public static bool GetState(VirtualKeys Key)
 {
     return (GetKeyState((int)Key) == 1);
 }
Exemplo n.º 42
0
		private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
Exemplo n.º 43
0
			/// <summary>Called when a virtual key is released.</summary>
			internal abstract void KeyUp(VirtualKeys key);
Exemplo n.º 44
0
		internal virtual bool IsKeyLocked (VirtualKeys key) { return false; }
Exemplo n.º 45
0
 /// <summary>Is called when a key is pressed.</summary>
 /// <param name="key">The key.</param>
 internal override void KeyDown(VirtualKeys key)
 {
     switch (key) {
         case VirtualKeys.B1:
             // --- reset the system ---
             if ((this.State == States.Brake | this.State == States.Service | this.State == States.Emergency) & this.Train.Handles.Reverser == 0 & this.Train.Handles.PowerNotch == 0 & this.Train.Handles.BrakeNotch >= this.Train.Specs.BrakeNotches) {
                 foreach (Pattern pattern in this.Patterns) {
                     if (Math.Abs(this.Train.State.Speed.MetersPerSecond) >= pattern.WarningPattern) {
                         pattern.Clear();
                     }
                 }
                 this.State = States.Normal;
                 this.Train.Sounds.AtsPBell.Play();
             }
             break;
         case VirtualKeys.B2:
             // --- brake release ---
             if ((this.State == States.Normal | this.State == States.Pattern) & !BrakeRelease & DurationOfBrakeRelease > 0.0) {
                 BrakeRelease = true;
                 BrakeReleaseCountdown = DurationOfBrakeRelease;
                 this.Train.Sounds.AtsPBell.Play();
             }
             break;
     }
 }
Exemplo n.º 46
0
		private void SetState (VirtualKeys key, bool state)
		{
			if (VirtualKeys.VK_NUMLOCK == key)
				num_state = state;
			else
				cap_state = state;
		}
Exemplo n.º 47
0
 public static extern short GetAsyncKeyState(VirtualKeys vKey);
Exemplo n.º 48
0
		private void GenerateMessage (VirtualKeys vkey, int scan, int key_code, XEventName type, int event_time)
		{
			bool state = (vkey == VirtualKeys.VK_NUMLOCK ? num_state : cap_state);
			KeybdEventFlags up, down;

			if (state) {
				// The INTERMEDIARY state means : just after a 'press' event, if a 'release' event comes,
				// don't treat it. It's from the same key press. Then the state goes to ON.
				// And from there, a 'release' event will switch off the toggle key.
				SetState (vkey, false);
			} else {
				down = (vkey == VirtualKeys.VK_NUMLOCK ? KeybdEventFlags.ExtendedKey : KeybdEventFlags.None);
				up = (vkey == VirtualKeys.VK_NUMLOCK ? KeybdEventFlags.ExtendedKey :
						KeybdEventFlags.None) | KeybdEventFlags.KeyUp;
				if ((key_state_table [(int) vkey] & 0x1) != 0) { // it was on
					if (type != XEventName.KeyPress) {
						SendKeyboardInput (vkey, scan, key_code, down, event_time);
						SendKeyboardInput (vkey, scan, key_code, up, event_time);
						SetState (vkey, false);
						key_state_table [(int) vkey] &= unchecked ((byte) ~0x01);
					}
				} else {
					if (type == XEventName.KeyPress) {
						SendKeyboardInput (vkey, scan, key_code, down, event_time);
						SendKeyboardInput (vkey, scan, key_code, up, event_time);
						SetState (vkey, true);
						key_state_table [(int) vkey] |= 0x01;
					}
				}
			}
		}
Exemplo n.º 49
0
		private MSG SendKeyboardInput (VirtualKeys vkey, int scan, int keycode, KeybdEventFlags dw_flags, int time)
		{
			Msg message;

			if ((dw_flags & KeybdEventFlags.KeyUp) != 0) {
				bool sys_key = (key_state_table [(int) VirtualKeys.VK_MENU] & 0x80) != 0 &&
					      ((key_state_table [(int) VirtualKeys.VK_CONTROL] & 0x80) == 0);
				key_state_table [(int) vkey] &= unchecked ((byte) ~0x80);
				message = (sys_key ? Msg.WM_SYSKEYUP : Msg.WM_KEYUP);
			} else {
				if ((key_state_table [(int) vkey] & 0x80) == 0) {
					key_state_table [(int) vkey] ^= 0x01;
				}
				key_state_table [(int) vkey] |= 0x80;
				bool sys_key = (key_state_table [(int) VirtualKeys.VK_MENU] & 0x80) != 0 &&
					      ((key_state_table [(int) VirtualKeys.VK_CONTROL] & 0x80) == 0);
				message = (sys_key ? Msg.WM_SYSKEYDOWN : Msg.WM_KEYDOWN);
			}

			MSG msg = new MSG ();
			msg.message = message;
			msg.wParam = (IntPtr) vkey;
			msg.lParam = GenerateLParam (msg, keycode);
			return msg;
		}
Exemplo n.º 50
0
 public static void SetState(VirtualKeys Key, bool State)
 {
     if (State != GetState(Key))
     {
         keybd_event(
         (byte)Key,
         0x45,
         KEYEVENTF_EXTENDEDKEY | 0,
         0
         );
         keybd_event(
         (byte)Key,
         0x45,
         KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
         0
         );
     }
 }
Exemplo n.º 51
0
		/// <summary>Is called when a virtual key is released.</summary>
		/// <param name="key">The virtual key that was released.</param>
		public void KeyUp(VirtualKeys key) {
			// TODO: Your old KeyUp code goes here.
		}
Exemplo n.º 52
0
 internal static extern SHORT GetKeyState(VirtualKeys vKey);
Exemplo n.º 53
0
		internal override bool IsKeyLocked (VirtualKeys key)
		{
			return (Win32GetKeyState (key) & 1) == 1;
		}
Exemplo n.º 54
0
 internal static extern UINT MapVirtualKey(VirtualKeys vkey, MapVirtualKeyType uMapType);
Exemplo n.º 55
0
			/// <summary>Called when a virtual key is pressed.</summary>
			internal abstract void KeyDown(VirtualKeys key);
Exemplo n.º 56
0
 internal override void KeyDown(VirtualKeys key)
 {
 }
Exemplo n.º 57
0
		/// <summary>Is called when a key is pressed.</summary>
		/// <param name="key">The key.</param>
		internal override void KeyDown(VirtualKeys key) {
			switch (key) {
				case VirtualKeys.S:
					// --- acknowledge the alarm ---
					if (this.State == States.Alarm & this.Train.Handles.PowerNotch == 0 & this.Train.Handles.BrakeNotch >= this.Train.Specs.AtsNotch) {
						this.State = States.Chime;
					}
					break;
				case VirtualKeys.A1:
					// --- stop the chime ---
					if (this.State == States.Chime) {
						this.State = States.Normal;
					}
					break;
				case VirtualKeys.B1:
					// --- reset the system ---
					if (this.State == States.Emergency & this.Train.Handles.Reverser == 0 & this.Train.Handles.PowerNotch == 0 & this.Train.Handles.BrakeNotch == this.Train.Specs.BrakeNotches + 1) {
						this.State = States.Chime;
					}
					break;
			}
		}
Exemplo n.º 58
0
		/// <summary>Is called when a key is pressed.</summary>
		/// <param name="key">The key.</param>
		internal override void KeyDown(VirtualKeys key) {
			switch (key) {
				case VirtualKeys.A2:
					// --- acknowledge the EB ---
					if (this.Counter >= TimeUntilBell) {
						this.Counter = 0.0;
					}
					break;
			}
		}
Exemplo n.º 59
0
 static extern short GetKeyState(VirtualKeys nVirtKey);
Exemplo n.º 60
0
		internal static bool IsKeyLocked (VirtualKeys key)
		{
			#if DriverDebug || DriverDebugState
				Console.WriteLine ("IsKeyLocked ({0}): Called, Result={1}", key, driver.IsKeyLocked (key));
			#endif
			return driver.IsKeyLocked (key);
		}