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

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

            lock (mutex)
            {
                var key = GetScanCode(c);
                return(_keyboard.IsDown(key));
            }
        }
示例#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;
            }
        }
示例#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);
        }
示例#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);
        }
示例#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();
            }
        }
示例#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();
            }
        }
示例#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();
        }