示例#1
0
        public HotKeyEventArgs(IntPtr hotKeyParam)
        {
            var param = (uint)hotKeyParam.ToInt64();

            Key       = (Keys)((param & 0xffff0000) >> 16);
            Modifiers = (KeyModifier)(param & 0x0000ffff);
        }
示例#2
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == 0x0312)
            {
                Keys        key      = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
                KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
                int         id       = m.WParam.ToInt32();

                Debug.WriteLine($"id: {id}");
                // Debug.WriteLine($"modifier : {modifier}");
                // Debug.WriteLine($"key : {key}");


                var dev = Program.tuya.DevicesList.Where(dev => dev.Id == hotkeyBinding[id].DevId).FirstOrDefault();

                int state = dev.Dev_type == "scene" ? 0 : Convert.ToInt32(dev.Data.State);
                Program.tuya.ControlDevicesAsync(hotkeyBinding[id].DevId, state ^ 1);

                dev.Data.State = Convert.ToBoolean(state ^ 1);
                RefreshDevicesList();
                Program.tuya.SaveDeviceData();
            }
        }
示例#3
0
        public void ReloadHotkeys()
        {
            UnregisterHotKeys();

            foreach (HotKey hotKey in (HotKey[])Enum.GetValues(typeof(HotKey)))
            {
                Keys key = Keys.None;
                try
                {
                    switch (hotKey)
                    {
                    case HotKey.StartStop: key = Properties.Settings.Default.StartStopHotKey; break;

                    case HotKey.CursorCapture: key = Properties.Settings.Default.CursorCaptureHotKey; break;

                    default: continue;
                    }

                    KeyModifier modifiers = RemoveAndReturnModifiers(ref key);
                    Win32.RegisterHotKey(this.Handle, (int)hotKey, (int)modifiers, (int)key);
                } catch (Exception ex)
                {
                    Console.WriteLine("Unable to load Hotkey:" + key);
                }
            }
        }
示例#4
0
    /// <summary>
    /// Create a new instance of <see cref="KeyboardInput"/> that handles specified keyboard key.
    /// </summary>
    /// <param name="key">Keyboard key.</param>
    /// <param name="modifiers">Key modifiers.</param>
    public KeyboardInput(KeyCode key = KeyCode.None, KeyModifier modifiers = KeyModifier.NoModifier)
    {
        mKey       = key;
        mModifiers = modifiers;

        mCachedToString = null;
    }
示例#5
0
        public void HandleInput(Keys key, KeyModifier modifer)
        {
            Vector3 moveVector = new Vector3(0);

            if (key == Keys.Up)
            {
                moveVector += new Vector3(0, 0, -1);
            }
            if (key == Keys.Down)
            {
                moveVector += new Vector3(0, 0, 1);
            }
            if (key == Keys.Left)
            {
                moveVector += new Vector3(-1, 0, 0);
            }
            if (key == Keys.Right)
            {
                moveVector += new Vector3(1, 0, 0);
            }
            if (key == Keys.F)
            {
                moveVector += new Vector3(0, -1, 0);
            }
            if (key == Keys.B)
            {
                moveVector += new Vector3(0, 1, 0);
            }

            _IsceneContent.UpdateCameraPostion(moveVector * _amount);
        }
示例#6
0
        private void AddAction(KeyModifier keyModifier, string keyName, string operationName, Action action)
        {
            var shortcut  = KeyService.GetShortcut(GetTestKey(keyName), keyModifier);
            var operation = new Operation(operationName, action);

            KeyService.RegisterShortcut(shortcut, operation);
        }
示例#7
0
        public static void RegisterHotKey(List <string> keys, Action <HotKey> action)
        {
            KeyModifier mod1 = KeyModifier.None;
            KeyModifier mod2 = KeyModifier.None;
            Key         key  = Key.None;

            Enum.TryParse(keys[0], out mod1);

            if (keys.Count > 2)
            {
                Enum.TryParse(keys[1], out mod2);
                Enum.TryParse(keys[2], out key);
            }
            else if (keys.Count == 2)
            {
                Enum.TryParse(keys[1], out key);
            }

            HotKey hotkey;

            if (mod1 != KeyModifier.None && mod2 != KeyModifier.None && key != Key.None)
            {
                hotkey = new HotKey(key, mod2 | mod1, action);
            }
            else if (mod1 != KeyModifier.None && key != Key.None)
            {
                hotkey = new HotKey(key, mod1, action);
            }
        }
 private void UpdateModifier(WinKey key, bool down)
 {
     if (down)
     {
         if (key == WinKey.LShiftKey || key == WinKey.RShiftKey || key == WinKey.ShiftKey || key == WinKey.Shift)
         {
             Modifier |= KeyModifier.Shift;
         }
         else if (key == WinKey.LControlKey || key == WinKey.RControlKey || key == WinKey.ControlKey || key == WinKey.Control)
         {
             Modifier |= KeyModifier.Control;
         }
         else if (key == WinKey.Alt)
         {
             Modifier |= KeyModifier.Alt;
         }
     }
     else
     {
         if (key == WinKey.LShiftKey || key == WinKey.RShiftKey || key == WinKey.ShiftKey || key == WinKey.Shift)
         {
             Modifier ^= KeyModifier.Shift;
         }
         else if (key == WinKey.LControlKey || key == WinKey.RControlKey || key == WinKey.ControlKey || key == WinKey.Control)
         {
             Modifier ^= KeyModifier.Control;
         }
         else if (key == WinKey.Alt)
         {
             Modifier ^= KeyModifier.Alt;
         }
     }
 }
        public bool Block(int keyCode, KeyModifier modifier, KeyState state)
        {
            var block = false;
            var key   = KeyInterop.KeyFromVirtualKey(keyCode);

            block |= key == Key.Apps;
            block |= key == Key.Escape && modifier == KeyModifier.None && !settings.AllowEsc;
            block |= key == Key.F1 && !settings.AllowF1;
            block |= key == Key.F2 && !settings.AllowF2;
            block |= key == Key.F3 && !settings.AllowF3;
            block |= key == Key.F4 && !settings.AllowF4;
            block |= key == Key.F5 && !settings.AllowF5;
            block |= key == Key.F6 && !settings.AllowF6;
            block |= key == Key.F7 && !settings.AllowF7;
            block |= key == Key.F8 && !settings.AllowF8;
            block |= key == Key.F9 && !settings.AllowF9;
            block |= key == Key.F10 && !settings.AllowF10;
            block |= key == Key.F11 && !settings.AllowF11;
            block |= key == Key.F12 && !settings.AllowF12;
            block |= key == Key.LWin && !settings.AllowSystemKey;
            block |= key == Key.PrintScreen && !settings.AllowPrintScreen;
            block |= key == Key.RWin && !settings.AllowSystemKey;
            block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.Escape && !settings.AllowAltEsc;
            block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.F4 && !settings.AllowAltF4;
            block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.Space;
            block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.Tab && !settings.AllowAltTab;
            block |= modifier.HasFlag(KeyModifier.Ctrl) && key == Key.Escape && !settings.AllowCtrlEsc;

            if (block)
            {
                Log(key, keyCode, modifier, state);
            }

            return(block);
        }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HotKeyBinding"/> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="key">The key.</param>
 /// <param name="keyModifiers">The key modifiers.</param>
 /// <param name="action">The action.</param>
 public HotKeyBinding(int id, Key key, KeyModifier keyModifiers, Action action)
 {
     this.Key = key;
     this.KeyModifiers = keyModifiers;
     this.Action = action;
     this.Id = id;
 }
示例#11
0
        void KeyPressHandler(Keys key, KeyModifier modifier)
        {
            String cameraName = "";

            if (key == Keys.N)
            {
                cameraName = "NearCamera";
            }
            else if (key == Keys.F)
            {
                cameraName = "FarCamera";
            }
            else if (key == Keys.C)
            {
                cameraName = "ChasingCamera";
            }

            if (!cameraName.Equals(""))
            {
                CameraNode cam = (CameraNode)scene.GetNode(cameraName);

                // Set the selected camera to be our active camera
                scene.CameraNode = cam;
            }
        }
示例#12
0
        //========================================================================================
        // Methods
        //========================================================================================

        /// <summary>
        /// Returns a string describining the specified key sequence.
        /// </summary>
        /// <param name="code">The primary keyboard key-code identifier.</param>
        /// <param name="modifier">The secondary keyboard key modifier.</param>
        /// <returns>A string desribining the key sequence.</returns>

        public static string MakeString(Keys code, KeyModifier modifier)
        {
            StringBuilder builder = new StringBuilder();

            if ((int)modifier != 0)
            {
                bool isMod = (
                    (code == Keys.Alt) ||
                    (code == Keys.LControlKey) || (code == Keys.RControlKey) ||
                    (code == Keys.LWin) || (code == Keys.RWin));

                if (!isMod)
                {
                    builder.Append(modifier.ToString());
                    builder.Append("+");
                }
            }

            string codes = code.ToString();

            if (codes.StartsWith("oem", StringComparison.InvariantCultureIgnoreCase))
            {
                codes = Char.ToUpper(codes[3], CultureInfo.CurrentCulture) + codes.Substring(4);
            }

            builder.Append(codes);

            return(builder.ToString());
        }
        private KeyModifier GetKeyModifiers()
        {
            KeyModifier modifiers = 0;
            var         kbState   = DualityApp.Keyboard;

            if (kbState.KeyPressed(Key.ShiftLeft) ||
                kbState.KeyPressed(Key.ShiftRight))
            {
                modifiers |= KeyModifier.Shift;
            }

            if (kbState.KeyPressed(Key.ControlLeft) ||
                kbState.KeyPressed(Key.ControlRight))
            {
                modifiers |= KeyModifier.Control;
            }

            if (kbState.KeyPressed(Key.AltLeft) ||
                kbState.KeyPressed(Key.AltRight))
            {
                modifiers |= KeyModifier.Alt;
            }

            return(modifiers);
        }
 public void SetHotKeyText(KeyCode hotkey, KeyModifier modifier)
 {
     _keybind.KeyCode  = hotkey;
     _keybind.Modifier = modifier;
     // todo add in some handling for special cases like space, numpad, and keyboard-number values;
     if (modifier.HasFlag(KeyModifier.None))
     {
         HotKeyModifierText.text         = "";
         HotKeyShiftModifierText.enabled = false;
         HotKeyText.text           = "";
         HotKeyTextNoModifier.text = hotkey.ToString();
     }
     else
     {
         if (modifier.HasFlag(KeyModifier.Shift))
         {
             HotKeyShiftModifierText.enabled = false;
             HotKeyModifierText.text         = "";
         }
         else
         {
             HotKeyShiftModifierText.enabled = false;
             if (modifier.HasFlag(KeyModifier.Alt))
             {
                 HotKeyModifierText.text = "A";
             }
             else
             {
                 HotKeyModifierText.text = "C";
             }
         }
         HotKeyText.text           = hotkey.ToString();
         HotKeyTextNoModifier.text = "";
     }
 }
示例#15
0
        /// <summary>
        /// Sets the char value for the specified key and key modifier combination
        /// </summary>
        /// <param name="key">The key for which to set the corresponding char value</param>
        /// <param name="mod">The key modifier for which to set the corresponding char value</param>
        /// <param name="ch">The char value to set for the specified key and key modifier</param>
        public static void SetCharacter(Keys key, KeyModifier mod, char ch)
        {
            if (!mMap.ContainsKey(key))
                mMap.Add(key, new Dictionary<KeyModifier, char>());

            mMap[key][mod] = ch;
        }
示例#16
0
        public static Key ToKey(this KeyModifier modKey)
        {
            switch (modKey)
            {
            case KeyModifier.None:
                return(Key.None);

            case KeyModifier.LeftCtrl:
                return(Key.LeftCtrl);

            case KeyModifier.RightCtrl:
                return(Key.RightCtrl);

            case KeyModifier.LeftShift:
                return(Key.LeftShift);

            case KeyModifier.RightShift:
                return(Key.RightShift);

            case KeyModifier.LeftWin:
                return(Key.LWin);

            case KeyModifier.RightWin:
                return(Key.RWin);

            default:
                return(Key.None);
            }
        }
        private void Log(Key key, int keyCode, KeyModifier modifier, KeyState state)
        {
            var modifierFlags = Enum.GetValues(typeof(KeyModifier)).OfType <KeyModifier>().Where(m => m != KeyModifier.None && modifier.HasFlag(m));
            var modifiers     = modifierFlags.Any() ? String.Join(" + ", modifierFlags) + " + " : string.Empty;

            logger.Info($"Blocked '{modifiers}{key}' ({key} = {keyCode}) when {state.ToString().ToLower()}.");
        }
 public bool IsEditingKeyPressed(KeyModifier eKeyMod)
 {
     bool bAnyModifier = eKeyMod == KeyModifier.Alt || eKeyMod == KeyModifier.Ctrl || eKeyMod == KeyModifier.Shift;
       if (EditorManager.Settings.CameraStyle==EditorSettingsBase.CameraStyle_e.MaxStyle)
     return !bAnyModifier;
       return bAnyModifier;
 }
示例#19
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM_HOTKEY)
            {
                Keys        key      = (Keys)(((int)m.LParam >> 16) & 0xFFFF);      // The key of the hotkey that was pressed.
                KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);       // The modifier of the hotkey that was pressed.
                int         id       = m.WParam.ToInt32();                          // The id of the hotkey that was pressed.

                if (id == (int)HotKey.StartStop)
                {
                    Task.Factory.StartNew(async() =>
                    {
                        try
                        {
                            await m_manager.StartOrStop();
                        }
                        catch (TaskCanceledException)
                        {
                            // Do nothing, cancellations are to be expected
                        }
                    },
                                          System.Threading.CancellationToken.None,
                                          TaskCreationOptions.None,
                                          TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
        }
示例#20
0
        /// <summary>
        /// Adds the posibility to add global shortcuts
        /// </summary>
        /// <param name="m">The type of message you want to use</param>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == 0x0312)
            {
                if ((DateTime.UtcNow - LastExecution).TotalSeconds > SHORTCUT_DELAY)
                {
                    Keys        key      = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
                    KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
                    int         id       = m.WParam.ToInt32();

                    if (!SettingsOpen)
                    {
                        int currentID = NextID();
                        SelectDevice(currentID);
                        foreach (var tuple in GetDevices().Where(tuple => currentID == tuple.Item1))
                        {
                            trayIcon.Text = "Active:" + " " + tuple.Item2;
                            if (Notifications)
                            {
                                Alert(ToolTipIcon.Info, "AudioSwitch", "Active device has been switched");
                            }
                            break;
                        }
                    }
                }
                LastExecution = DateTime.UtcNow;
            }
        }
示例#21
0
 public void Instance_KeyPress(Keys key, KeyModifier target)
 {
     if (Keys.Z == key)
     {
         if (baseClass.staticCamera.FieldOfViewY < MathHelper.ToRadians(180))
         {
             baseClass.staticCamera.FieldOfViewY = baseClass.staticCamera.FieldOfViewY + (float)0.01;
         }
         else
         {
             baseClass.staticCamera.FieldOfViewY = MathHelper.ToRadians(45);
         }
     }
     if (Keys.X == key)
     {
         if (baseClass.staticCamera.FieldOfViewY > 0)
         {
             baseClass.staticCamera.FieldOfViewY = baseClass.staticCamera.FieldOfViewY - (float)0.01;
         }
         else
         {
             baseClass.staticCamera.FieldOfViewY = MathHelper.ToRadians(45);
         }
     }
 }
示例#22
0
 public override bool OnMouseUp(MouseEventArgs e, KeyModifier eKeyMod, int iOldX, int iOldY)
 {
     base.OnMouseUp(e, eKeyMod, iOldX, iOldY);
       if (e.Button == MouseButtons.Left)// && eKeyMod != KeyModifier.None)
     HandleClick();
       return true;
 }
示例#23
0
 /// <summary>
 /// cTor:
 /// </summary>
 /// <param name="key">A virtual Key</param>
 /// <param name="modifiers">A Modifier Map</param>
 /// <param name="tag">A unique tag</param>
 /// <param name="onKey">A method to call (arg will be the tag when called)</param>
 public HotkeyItem(Keys key, KeyModifier modifiers, string tag, Action <string> onKey)
 {
     _virtualKey   = (int)key;
     _keyModifiers = modifiers;
     Tag           = tag;
     _OnKey        = onKey;
 }
示例#24
0
        protected override bool Process(Key key, KeyModifier modifier, KeyState state)
        {
            var changed = false;
            var pressed = state == KeyState.Pressed;

            switch (key)
            {
            case Key.Q:
                changed = Q != pressed;
                Q       = pressed;
                break;

            case Key.LeftCtrl:
                changed  = LeftCtrl != pressed;
                LeftCtrl = pressed;
                break;

            case Key.RightCtrl:
                changed   = RightCtrl != pressed;
                RightCtrl = pressed;
                break;
            }

            if (Q && (LeftCtrl || RightCtrl) && changed && !modifier.HasFlag(KeyModifier.Alt))
            {
                logger.Debug("Detected termination sequence.");
                Activated?.Invoke();

                return(true);
            }

            return(false);
        }
示例#25
0
 /// <summary>
 /// All in one method to Test and Call when it matches
 /// </summary>
 /// <param name="key">A virtual Key</param>
 /// <param name="modMap">A Modifier Map</param>
 public void TestAndCall(int key, KeyModifier modMap)
 {
     if (HitTest(key, modMap))
     {
         OnKey( );
     }
 }
示例#26
0
文件: Form1.cs 项目: drhoang999/LTTQ
        protected override void WndProc(ref Message m)
        {
            try
            {
                base.WndProc(ref m);

                if (m.Msg == 0x0312)
                {
                    Keys        key      = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
                    KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
                    int         id       = m.WParam.ToInt32();

                    switch (id)
                    {
                    case 2:
                    {
                        Quay();
                        break;
                    }

                    case 3:
                    {
                        camerapic_Click(this, new EventArgs());
                        break;
                    }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
示例#27
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM_HOTKEY)
            {
                Keys        key      = (Keys)(((int)m.LParam >> 16) & 0xFFFF);      // The key of the hotkey that was pressed.
                KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);       // The modifier of the hotkey that was pressed.
                int         id       = m.WParam.ToInt32();                          // The id of the hotkey that was pressed.

                if (id == (int)HotKey.StartStop)
                {
                    if (m_manager.IsStoppedOrPaused())
                    {
                        btnStart_Click(null, null);
                    }
                    else
                    {
                        btnStop_Click(null, null);
                    }
                }
                else if (id == (int)HotKey.PauseResume)
                {
                    btnStart_Click(null, null);
                }
            }
        }
示例#28
0
 private void Instance_KeyPressEvent(Keys key, KeyModifier modifier)
 {
     if (key == Keys.Escape)
     {
         this.Exit();
     }
 }
示例#29
0
        /// <summary>
        /// Add a Hotkey to the list (no checks for potentially problematic cases here..)
        ///  NOTE: The Action may only last some milliseconds, else the KeyHook will be unhooked by Windows (see doc)
        /// </summary>
        /// <param name="key">A virtual Key</param>
        /// <param name="modifierPattern">The Key Modifier pattern</param>
        /// <param name="tag">A unique ID</param>
        /// <param name="onKey">An Action(string) which is exec when the Hotkey is pressed</param>
        public void AddKey(Keys key, KeyModifier modifierPattern, string tag, Action <string> onKey)
        {
            RemoveKey(tag);
            var item = new HotkeyItem(key, modifierPattern, tag, onKey);

            _cat.Add(tag, item);
        }
示例#30
0
        /// <summary>
        /// Catch the Ctrl + F12 Macro and execute!
        /// </summary>
        protected override void WndProc(ref Message m)
        {
            try
            {
                base.WndProc(ref m);

                if (m.Msg == 0x0312)
                {
                    /* Note that the three lines below are not needed if you only want to register one hotkey.
                     * The below lines are useful in case you want to register multiple keys, which you can use a switch with the id as argument,
                     * or if you want to know which key/modifier was pressed for some particular reason. */
                    Keys        key      = (Keys)(((int)m.LParam >> 16) & 0xFFFF);      // The key of the hotkey that was pressed.
                    KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);       // The modifier of the hotkey that was pressed.
                    var         id       = m.WParam.ToInt32();                          // The id of the hotkey that was pressed.

                    // do something
                    if (id == 0 && ButtonGenerate.Enabled)
                    {
                        ButtonGenerateClick(null, null);
                    }
                }
            }
            catch
            {
                UnregisterHotKey(Handle, 0);
                WndProc(ref m);
            }
        }
示例#31
0
        // Handle global hotkey press
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == 0x0312)
            {
                Keys        key      = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
                KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
                int         id       = m.WParam.ToInt32();

                switch (key)
                {
                case Keys.S:
                    Start_Click(this, new EventArgs());
                    break;

                case Keys.F:
                    Finish_Click(this, new EventArgs());
                    break;

                case Keys.E:
                    Pause_Click(this, new EventArgs());
                    break;

                case Keys.R:
                    Reset_Click(this, new EventArgs());
                    break;
                }
            }
        }
示例#32
0
 public KeyRegistration(KeyModifier m, Keys k, UnityAction <KeyModifier, Keys> l)
 {
     Modifier   = m;
     Key        = k;
     Listener   = l;
     Registered = false;
 }
        /// <summary>
        /// Registers the hotkey.
        /// </summary>
        /// <param name="modifier">Hotkey modifier.</param>
        /// <param name="key">Hotkey key.</param>
        private void RegisterGlobalHotkey(KeyModifier modifier, System.Windows.Forms.Keys key)
        {
            UnregisterGlobalHotkey();

            try
            {
                // use the GlobalAddAtom API to get a unique ID (as suggested by MSDN)
                string atomName = Thread.CurrentThread.ManagedThreadId.ToString("X8") + this.GetType().FullName;
                ID = GlobalAddAtom(atomName);
                if (ID == 0)
                {
                    throw new Exception("Unable to generate unique hotkey ID. Error: " + Marshal.GetLastWin32Error().ToString());
                }

                // register the hotkey, throw if any error
                if (!RegisterHotKey(this.Helper.Handle, ID, (uint)modifier, (uint)key))
                {
                    throw new Exception("Unable to register hotkey. Error: " + Marshal.GetLastWin32Error().ToString());
                }

                Key       = key;
                Modifiers = modifier;
                GlobalHotkey.RegisterNewHotkey(this);
            }
            catch (Exception ex)
            {
                // clean up if hotkey registration failed
                Dispose();
                Console.WriteLine(ex);
            }
        }
        protected override bool Process(Key key, KeyModifier modifier, KeyState state)
        {
            var changed = false;
            var pressed = state == KeyState.Pressed;

            switch (key)
            {
            case Key.A:
                changed = A != pressed;
                A       = pressed;
                break;

            case Key.LWin:
                changed     = LeftWindows != pressed;
                LeftWindows = pressed;
                break;
            }

            if (A && LeftWindows && changed)
            {
                logger.Debug("Detected toggle sequence for action center.");
                Toggled?.Invoke();

                return(true);
            }

            return(false);
        }
示例#35
0
 // ******************************************************************
 public HotKey(IntPtr window, Key k, KeyModifier keyModifiers, Action<HotKey> action)
 {
     this.key = k;
     this.keyModifiers = keyModifiers;
     this.action = action;
     this.window = window;
     Register();
 }
示例#36
0
        /// <summary>
        /// Registers a hot key in the system.
        /// </summary>
        ///  <param name="modifier">The modifiers that are associated with the hot key.</param>
        /// <param name="key">The key itself that is associated with the hot key.</param>
        public void RegisterHotKey(KeyModifier modifier, Keys key)
        {
            // increment the counter.
            _currentId = _currentId + 1;

            // register the hot key.
            if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
                throw new InvalidOperationException("Couldn’t register the hot key.");
        }
示例#37
0
        //========================================================================================
        // Constructor
        //========================================================================================
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="action">The action associated with this key sequence.</param>
        /// <param name="hotID">The internal unique ID to assign to this instance.</param>
        /// <param name="code">The primary keyboard key-code identifier.</param>
        /// <param name="modifier">The secondary keyboard modifier such as Ctrl or Alt.</param>
        public HotKey(HotKeyAction action, Keys code, KeyModifier modifier)
        {
            counter++;

            this.Action = action;
            this.HotID = counter;
            this.Code = code;
            this.Modifier = modifier;
        }
示例#38
0
 // ******************************************************************
 public HotKey(Key k, KeyModifier keyModifiers, Action<HotKey> action, bool register = true)
 {
     Key = k;
     KeyModifiers = keyModifiers;
     Action = action;
     if(register) {
         Register();
     }
 }
示例#39
0
 // ******************************************************************
 public KeyboardHook(Key k, KeyModifier keyModifiers, Action<KeyboardHook> action, bool register = true)
 {
     Key = k;
     KeyModifiers = keyModifiers;
     Action = action;
     if (register)
     {
         Register();
     }
 }
示例#40
0
        /// <summary>
        /// Retrieves the char value for the specified key and key modifier combination.
        /// If a char is registered for said combination, then the char is assigned to
        /// 'ch' and true is returned. False is returned otherwise and 'ch' is unassigned.
        /// </summary>
        /// <param name="key">The key for which to retrieve the corresponding char value</param>
        /// <param name="mod">The key modifier for the specified key</param>
        /// <param name="ch">Will contain the requested char value for the specified key
        /// and key modifier if such a value exists in the key map, or will be unassigned
        /// if no such char value is registered</param>
        /// <returns>True if the char value for the specified key and key modifier combination
        /// was retrieved and stored in 'ch', false otherwise</returns>
        public static bool GetCharacter(Keys key, KeyModifier mod, ref char ch)
        {
            if (!mMap.ContainsKey(key))
                return false;

            if (!mMap[key].ContainsKey(mod))
                return false;

            ch = mMap[key][mod];

            return true;
        }
    /// <summary>
    /// Create a new instance of <see cref="MouseInput"/> that handles specified mouse button.
    /// </summary>
    /// <param name="button">Mouse button.</param>
    /// <param name="modifiers">Key modifiers.</param>
    public MouseInput(MouseButton button, KeyModifier modifiers =KeyModifier.NoModifier)
    {
        if (button == MouseButton.None)
        {
            Debug.LogError("button can't be MouseButton.None");
        }

        mAxis      = MouseAxis.None;
        mButton    = button;
        mModifiers = modifiers;

        mCachedToString = null;
    }
    /// <summary>
    /// Create a new instance of <see cref="MouseInput"/> that handles specified mouse axis.
    /// </summary>
    /// <param name="axis">Mouse axis.</param>
    /// <param name="modifiers">Key modifiers.</param>
    public MouseInput(MouseAxis axis, KeyModifier modifiers = KeyModifier.NoModifier)
    {
        if (axis == MouseAxis.None)
        {
            Debug.LogError("axis can't be MouseAxis.None");
        }

        mAxis      = axis;
        mButton    = MouseButton.None;
        mModifiers = modifiers;

        mCachedToString = null;
    }
    /// <summary>
    /// Create a new instance of <see cref="JoystickInput"/> that handles specified joystick button for a target joystick.
    /// </summary>
    /// <param name="button">Joystick button.</param>
    /// <param name="target">Target joystick.</param>
    /// <param name="modifiers">Key modifiers.</param>
    public JoystickInput(JoystickButton button, Joystick target = Joystick.AllJoysticks, KeyModifier modifiers = KeyModifier.NoModifier)
    {
        if (button == JoystickButton.None)
        {
            Debug.LogError("button can't be JoystickButton.None");
        }

        mAxis      = JoystickAxis.None;
        mButton    = button;
        mTarget    = target;
        mModifiers = modifiers;

        mCachedToString  = null;
        mCachedInputName = null;
    }
        /// <summary>Register the hotkey</summary>
        public void RegisterGlobalHotKey(int hotkey, KeyModifier modifier)
        {
            UnregisterGlobalHotKey();

            try
            {
                // use the GlobalAddAtom API to get a unique ID (as suggested by MSDN)
                string atomName = Thread.CurrentThread.ManagedThreadId.ToString("X8") + this.GetType().FullName;
                HotkeyID = GlobalAddAtom(atomName);
                if (HotkeyID == 0)
                    throw new Exception("Unable to generate unique hotkey ID. Error: " + Marshal.GetLastWin32Error().ToString());

                // register the hotkey, throw if any error
                if (!RegisterHotKey(this.Handle, HotkeyID, (uint)modifier, (uint)hotkey))
                    throw new Exception("Unable to register hotkey. Error: " + Marshal.GetLastWin32Error().ToString());

            }
            catch (Exception ex)
            {
                // clean up if hotkey registration failed
                Dispose();
                Console.WriteLine(ex);
            }
        }
示例#45
0
 public HotKeyEventArgs(Keys key, KeyModifier modifiers)
 {
     Key = key;
     Modifiers = modifiers;
 }
示例#46
0
 public KeyMask(KeyModifier modifier, Keys key)
 {
     this.modifier = modifier;
       this.key = key;
 }
示例#47
0
    /// <summary>
    /// Verifies that specified key modifiers are active during current frame.
    /// </summary>
    /// <returns>Specified key modifiers are active during current frame.</returns>
    /// <param name="exactKeyModifiers">If set to <c>true</c> check that only specified key modifiers are active, otherwise check that at least specified key modifiers are active.</param>
    protected bool checkModifiers(bool exactKeyModifiers = false)
    {
        if (!exactKeyModifiers && mModifiers == KeyModifier.NoModifier)
        {
            return true;
        }

        if (mCachedModifiersFrame != Time.frameCount)
        {
            KeyModifier res = KeyModifier.NoModifier;

            if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
            {
                res |= KeyModifier.Ctrl;
            }

            if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
            {
                res |= KeyModifier.Alt;
            }

            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                res |= KeyModifier.Shift;
            }

            mCachedModifiersFrame = Time.frameCount;
            mCachedModifiersState = res;
        }

        if (exactKeyModifiers)
        {
            return mModifiers == mCachedModifiersState;
        }
        else
        {
            return (mModifiers & mCachedModifiersState) == mModifiers;
        }
    }
示例#48
0
        public override bool OnPick(MouseEventArgs e, KeyModifier eKeyMod)
        {
            base.OnPick(e, eKeyMod);
              if (!bResultValid)
            return true;

              // escalate to the next click
              EditorManager.ActiveView.PickHandler = new MeasureToolPickerEnd(this);
              return true;
        }
        public override bool OnMouseDown(System.Windows.Forms.MouseEventArgs e, KeyModifier eKeyMod, int iOldX, int iOldY)
        {
            _bIsPainting = true;

              if (_resizeBrushKeyDown)
              {
            _bIsPainting = false;
              }

              if (_bIsPainting)
              {
            TerrainEditor.BeginUpdatePainting();
              }

              return base.OnMouseDown(e, eKeyMod, iOldX, iOldY);
        }
 /// <summary>When key+modifier combination km is pressed perform msg. (Scintilla feature 2070)</summary>
 public void AssignCmdKey(KeyModifier km, int msg)
 {
     IntPtr res = Win32.SendMessage(scintilla, SciMsg.SCI_ASSIGNCMDKEY, km.Value, msg);
 }
示例#51
0
 public void OnHotKey(Keys k, KeyModifier modifier)
 {
     try
     {
         switch (k)
         {
             case Keys.D2:
                 this.PerformScreenshotCurrentWindow();
                 break;
             case Keys.D3:
                 this.PerformScreenshot(false);
                 break;
             case Keys.D4:
                 this.PerformScreenshot(true);
                 break;
             case Keys.D5:
                 this.UploadFromClipboard();
                 break;
         }
     }
     catch (Exception e)
     {
         HandleError("Error occured taking a screenshot:", e);
     }
 }
示例#52
0
        public override bool OnMouseWheel(System.Windows.Forms.MouseEventArgs e, KeyModifier eKeyMod, int iOldX, int iOldY)
        {
            if (eKeyMod == KeyModifier.Ctrl)
              {
            float fZoomScale = e.Delta > 0 ? 2.0f : 0.5f;
            fZoom *= fZoomScale;
            if (fZoom < 0.125f)
              fZoom = 0.125f;
            if (fZoom > 8.0f)
              fZoom = 8.0f;
            Picking.SetZoom(fZoom);
              }
              else
            base.OnMouseWheel(e, eKeyMod, iOldX, iOldY); // move camera

              return true;
        }
 public override void OnKeyModifierChanged(KeyModifier eOldMod, KeyModifier eNewMod)
 {
     base.OnKeyModifierChanged(eOldMod, eNewMod);
       _keyMod = eNewMod;
 }
 /// <summary>When key+modifier combination km is pressed do nothing. (Scintilla feature 2071)</summary>
 public void ClearCmdKey(KeyModifier km)
 {
     IntPtr res = Win32.SendMessage(scintilla, SciMsg.SCI_CLEARCMDKEY, km.Value, Unused);
 }
示例#55
0
        /// <summary>
        /// Sets the buttonstate and calls the OnMouse*() events for the ActiveView.
        /// </summary>
        /// <param name="button">button to press/release.</param>
        /// <param name="buttonState">new state of the button.</param>
        /// <param name="keyModifier">the key modifier to use.</param>
        public void SetButtonState(MouseButtons button, bool buttonPressed, KeyModifier keyModifier)
        {
            Point screenPos = EditorApp.ActiveView.PointToClient(Cursor.Position);
              MouseEventArgs args = new MouseEventArgs(button, 1, screenPos.X, screenPos.Y, 0);

              switch (buttonPressed)
              {
            case true:
              EditorApp.ActiveView.CurrentContext.OnMouseDown(args, keyModifier, screenPos.X, screenPos.Y);
              break;
            case false:
              EditorApp.ActiveView.CurrentContext.OnMouseUp(args, keyModifier, screenPos.X, screenPos.Y);
              break;
              }
        }
示例#56
0
文件: HotKey.cs 项目: jaywick/Vizr
 public HotKey(Key k, KeyModifier keyModifiers)
 {
     Key = k;
     KeyModifiers = keyModifiers;
     Register();
 }
示例#57
0
        /// <summary>
        /// Unsets the char value for the specified key and key modifier combination
        /// </summary>
        /// <param name="key">The key for which to unset the corresponding char value</param>
        /// <param name="mod">The key modifier for which to unset the corresponding char value</param>
        /// <returns>The char value previously set for the specified key and key modifier, or the
        /// null character ('\0') if no char value was set for the combination</returns>
        public static char UnsetCharacter(Keys key, KeyModifier mod)
        {
            if (!mMap.ContainsKey(key))
                return '\0';

            if (!mMap[key].ContainsKey(mod))
                return '\0';

            char ch = mMap[key][mod];

            mMap[key].Remove(mod);

            if (mMap[key].Count == 0)
                mMap.Remove(key);

            return ch;
        }
示例#58
0
 public HotKeyEventArgs(IntPtr hotKeyParam)
 {
     var param = (uint)hotKeyParam.ToInt64();
     Key = (Keys)((param & 0xffff0000) >> 16);
     Modifiers = (KeyModifier)(param & 0x0000ffff);
 }
        public override bool OnMouseUp(System.Windows.Forms.MouseEventArgs e, KeyModifier eKeyMod, int iOldX, int iOldY)
        {
            if (_bIsPainting)
            TerrainEditor.FinishUpdatePainting();

              return base.OnMouseUp(e, eKeyMod, iOldX, iOldY);
        }
示例#60
0
 public override bool OnPick(MouseEventArgs e, KeyModifier eKeyMod)
 {
     base.OnPick(e, eKeyMod);
       if (bResultValid)
     EditorManager.ActiveView.PickHandler = new MeasureToolPickerViewResult(_start, this, "Click into view or press ESC to abort");
       return true;
 }