예제 #1
0
 protected virtual void OnHookEvent(HookEventArgs hookArgs, KeyBoardInfo keyBoardInfo)
 {
     if (HookEvent != null)
     {
         HookEvent(hookArgs, keyBoardInfo);
     }
 }
예제 #2
0
        private int HookProcedure(int code, IntPtr wParam, IntPtr lParam)
        {
            KBDLLHOOKSTRUCT hookStruct = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));

            if (code < 0)
            {
                return(CallNextHookEx(hookDeleg, code, wParam, lParam));
            }
            // Let clients determine what to do
            HookEventArgs e = new HookEventArgs();

            e.Code   = code;
            e.wParam = wParam;
            e.lParam = lParam;
            KeyBoardInfo keyInfo = new KeyBoardInfo();

            keyInfo.vkCode   = hookStruct.vkCode;
            keyInfo.scanCode = hookStruct.scanCode;
            OnHookEvent(e, keyInfo);
            // Yield to the next hook in the chain
            return(CallNextHookEx(hookDeleg, code, wParam, lParam));
        }
예제 #3
0
        private void HookEvent(HookEventArgs hookEventArgs, KeyBoardInfo keyBoardInfo)
        {
            var vkey = (Keys)keyBoardInfo.vkCode;

            if (!_keys.Contains(vkey))
            {
                _keys.Add(vkey);
            }

            if (_collecting)
            {
                return;
            }
            _collecting = true;

            var layer = ActiveView == null ? null : ActiveView.GetModel() as iLayer;
            var list  = ActiveView as SmoothListbox;

            Device.Thread.QueueWorker(o =>
            {
                Thread.Sleep(40);
                Device.Thread.ExecuteOnMainThread(new Action(() =>
                {
                    var currentKeystroke = new Keystroke(_keys.Cast <int>());
                    var candidateKeys    = new List <Keystroke> {
                        currentKeystroke
                    };
                    candidateKeys.AddRange(_keys.Select(k => new Keystroke((int)k)));

                    if (layer != null)
                    {
                        foreach (var key in candidateKeys)
                        {
                            var keyChord = new Gesture(key);

                            var link = layer.ShortcutGestures.GetValueOrDefault(keyChord, null);
                            if (link == null && _lastKeystroke != null)
                            {
                                keyChord = new Gesture(_lastKeystroke, key);
                                link     = layer.ShortcutGestures.GetValueOrDefault(keyChord, null);
                            }

                            if (link == null)
                            {
                                continue;
                            }
                            _keys.Clear();
                            currentKeystroke = null;
                            CompactFactory.Navigate(link, ActiveView);
                            break;
                        }
                    }

                    if (_keys.Contains(Keys.Tab))
                    {
                        if (list == null || list.IsDisposed)
                        {
                            return;
                        }
                        if (_keys.Contains(Keys.ShiftKey))
                        {
                            list.HighlightPrevious();
                        }
                        else
                        {
                            list.HighlightNext();
                        }
                        _keys.Clear();
                        currentKeystroke = null;
                    }
                    else if (_keys.Any())
                    {
                        UI.Controls.TextBox text     = null;
                        UI.Controls.TextArea area    = null;
                        UI.Controls.PasswordBox pass = null;
                        UI.Controls.DatePicker date  = null;
                        UI.Controls.TimePicker time  = null;

                        var item = list == null || list.IsDisposed ? null : list.SelectedItem;
                        if (item != null)
                        {
                            text = item.GetChild <UI.Controls.TextBox>();
                            area = item.GetChild <UI.Controls.TextArea>();
                            pass = item.GetChild <UI.Controls.PasswordBox>();
                            date = item.GetChild <UI.Controls.DatePicker>();
                            time = item.GetChild <UI.Controls.TimePicker>();
                        }

                        if (item == null || text == null && area == null && pass == null)
                        {
                            foreach (var key in _keys)
                            {
                                switch (key)
                                {
                                case Keys.Home:
                                    if (list != null && !list.IsDisposed)
                                    {
                                        list.ScrollToHome(true);
                                        _keys.Clear();
                                        currentKeystroke = null;
                                    }
                                    break;

                                case Keys.End:
                                    if (list != null && !list.IsDisposed)
                                    {
                                        list.ScrollToEnd(true);
                                        _keys.Clear();
                                        currentKeystroke = null;
                                    }
                                    break;

                                case Keys.F23:
                                case Keys.Select:
                                case Keys.Enter:
                                case Keys.Space:
                                    if (item != null)
                                    {
                                        item.Select();
                                    }
                                    _keys.Clear();
                                    currentKeystroke = null;
                                    break;
                                }

                                if (currentKeystroke == null)
                                {
                                    break;                           // _keys was modified
                                }
                            }
                        }

                        if (item == null || area == null && date == null && time == null)
                        {
                            foreach (var key in _keys)
                            {
                                switch (key)
                                {
                                case Keys.Up:
                                    if (list != null && !list.IsDisposed)
                                    {
                                        list.HighlightPrevious();
                                        _keys.Clear();
                                        currentKeystroke = null;
                                    }
                                    break;

                                case Keys.Down:
                                    if (list != null && !list.IsDisposed)
                                    {
                                        list.HighlightNext();
                                        _keys.Clear();
                                        currentKeystroke = null;
                                    }
                                    break;
                                }

                                if (currentKeystroke == null)
                                {
                                    break;                           // _keys was modified
                                }
                            }
                        }

                        if (area == null && text != null && (_keys.Contains(Keys.Enter) || _keys.Contains(Keys.F23)))
                        {
                            list.HighlightNext();
                            _keys.Clear();
                            currentKeystroke = null;
                        }

                        CommonKeys(list == null || list.IsDisposed ? null : list, ref currentKeystroke);
                    }

                    _lastKeystroke = currentKeystroke;

                    Device.Thread.QueueWorker(p =>
                    {
                        Thread.Sleep(40);
                        _keys.Clear();
                        _collecting = false;
                    });
                }));
            });
        }