Ejemplo n.º 1
0
 public void SetWindow(string window)
 {
     this.window = window;
     if (WinUtils.GetActiveWindow() != this.window)
     {
         Stop();
     }
 }
Ejemplo n.º 2
0
        public static void Send(Keyboard.ScanCodeShort key)
        {
            if (WinUtils.GetActiveWindow() != WindowToSendKeysIn || _currentKey != null)
            {
                return;
            }

            _currentKey = key;
            _keyboard.Send(_currentKey.Value);
            _timerCombination.Restart();
        }
Ejemplo n.º 3
0
        public static bool IsCharDown(char c)
        {
            if (WinUtils.GetActiveWindow() != WindowToSendKeysIn)
            {
                return(false);
            }

            lock (mutex)
            {
                var key = GetScanCode(c);
                return(_keyboard.IsDown(key));
            }
        }
Ejemplo n.º 4
0
        public static void SendCharUp(char c)
        {
            if (WinUtils.GetActiveWindow() != WindowToSendKeysIn || !_active)
            {
                return;
            }

            lock (mutex)
            {
                var key = GetScanCode(c);
                _keyboard.SendUp(key);
                _timerRepeat.Stop();
                _repeatKey = null;
            }
        }
Ejemplo n.º 5
0
        public void SendDown(ScanCodeShort key)
        {
            if (WinUtils.GetActiveWindow() != this.window)
            {
                Stop();
                return;
            }
            else if (IsKeyDownTimerActive(key))
            {
                Debug.Log("This key is already being pressed");
                return;
            }

            VirtualKeyShort code = GetVK(key);

            SendInput(code, key);
        }
Ejemplo n.º 6
0
        public static void SendMessage(string message, Action callback = null)
        {
            if (WinUtils.GetActiveWindow() != WindowToSendKeysIn || !_active)
            {
                return;
            }
            else if (_currentKey != null || string.IsNullOrEmpty(message))
            {
                return;
            }

            lock (mutex)
            {
                _currentCombination  = GetCombination(message);
                _callbackMultipleKey = callback;
            }

            OnKeyTimer(null, null);
        }
Ejemplo n.º 7
0
        public static void SendChar(char c, float duration = Keyboard.KEY_DOWN_TIME, Action callback = null)
        {
            if (WinUtils.GetActiveWindow() != WindowToSendKeysIn || !_active)
            {
                return;
            }

            lock (mutex)
            {
                if (_currentKey != null)
                {
                    return;
                }

                _currentKey = GetScanCode(c);
                _keyboard.SendUp(_currentKey.Value);
                _keyboard.Send(_currentKey.Value, duration, callback);
                _timerCombination.Restart();
            }
        }
Ejemplo n.º 8
0
        private void OnKeyDownTimerOver(object sender, ElapsedEventArgs e)
        {
            if (WinUtils.GetActiveWindow() != this.window)
            {
                Stop();
                return;
            }

            Timer timer = sender as Timer;

            timer.Stop();
            var tuple = TryGetTupleForTimer(timer);

            if (tuple != null)
            {
                VirtualKeyShort code = GetVK(tuple.Item1);
                SendInput(code, tuple.Item1, KEYEVENTF.KEYUP);
                tuple.Item2?.Invoke();
            }
        }
Ejemplo n.º 9
0
        public static void SendCombination(EKeyCombination keys, Action callback = null)
        {
            if (WinUtils.GetActiveWindow() != WindowToSendKeysIn)
            {
                return;
            }

            if (!_keyCombinations.ContainsKey(keys))
            {
                Debug.Log("Key map does not contain combination: " + keys.ToString());
                return;
            }

            if (_currentCombination != null)
            {
                Debug.Log("A combination is already running");
                return;
            }

            _callbackMultipleKey = callback;
            _currentCombination  = GetKeyCombinations(keys);
            _timerCombination.Restart();
        }