Esempio n. 1
0
        private static int GlobalHookCallback(HookType Type, int code, IntPtr wParam, IntPtr lParam)
        {
            switch (Type)
            {
            case HookType.WH_KEYBOARD_LL:
            {
                if (!KeyboardHooks.Dispatch(code, wParam, lParam))
                {
                    return(1);
                }
                break;
            }

            case HookType.WH_MOUSE_LL:
            {
                if (!MouseHooks.Dispatch(code, wParam, lParam))
                {
                    return(1);
                }
                break;
            }

            default:
                break;
            }

            return(User32.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
        }
Esempio n. 2
0
        public static void Uninstall()
        {
            lock (HookContainerLock)
            {
                KeyboardHooks.Remove();
                MouseHooks.Remove();

                foreach (var Handle in HooksHandlesByType)
                {
                    User32.UnhookWindowsHookEx(Handle.Value);
                }

                HooksHandlesByType.Clear();
            }
        }
Esempio n. 3
0
 private void BindHotKey()
 {
     hook             = KeyboardHooks.Create();
     hook.KeyPressed += hook_KeyPressed;
     hook.RegisterHotKey(options.ShortcutModifiers, options.ShortcutKey);
 }
Esempio n. 4
0
        public MainWindow()
        {
            InitializeComponent();

            QueryHandlers = new Dictionary <Type, QueryHandler>();

            ListBoxResults.SelectionMode = SelectionMode.Single;

            _hooks = new KeyboardHooks();
            _hooks.OnKeyPressed  += OnHookedKeyPressed;
            _hooks.OnKeyReleased += OnHookedKeyReleased;
            _hooks.HookKeyboard();

            HeightBarOnly = 87;
            HeightTotal   = Height;

            HideResultsPane();
            ResetLocation();

            QueryHandlers.Add(typeof(CommandQueryHandler), new CommandQueryHandler(this));
            QueryHandlers.Add(typeof(SystemQueryHandler), new SystemQueryHandler(this));
            QueryHandlers.Add(typeof(WebQueryHandler), new WebQueryHandler(this));

            Log.ReportMemoryUsage();
            foreach (KeyValuePair <Type, QueryHandler> qHandlers in QueryHandlers)
            {
                qHandlers.Value.OnQueryEnd     += (results, query) => { _lastQuery = query; };
                qHandlers.Value.OnScanComplete += () =>
                {
                    FrameLoadResults.Visibility = Visibility.Hidden;
                    Query(TextBoxSearchBar.Text.ToLower());
                };
                qHandlers.Value.Scan();
            }

            _queryTimer          = new DispatcherTimer();
            _queryTimer.Interval = new TimeSpan(0, 0, 0, 0, MIN_TIME_BETWEEN_QUERIES_MS);
            _queryTimer.Tick    += (sender, args) =>
            {
                if (_textChangedRecently)
                {
                    _textChangedRecently = false;
                    if (_lastQuery != TextBoxSearchBar.Text)
                    {
                        Query(TextBoxSearchBar.Text.ToLower());
                    }
                }
            };
            _queryTimer.Start();

            _previewer = new Previewer(PreviewGrid, PreviewImage, PreviewName, PreviewDesc);
            ListBoxResults.SelectionChanged += (sender, args) =>
            {
                if (ListBoxResults.SelectedIndex >= 0)
                {
                    UIResultItem item = (UIResultItem)ListBoxResults.SelectedItem;
                    if (item != null)
                    {
                        _previewer.PreviewFromQueryResultItem(item);
                    }
                    else
                    {
                        Log.Error("Selected item is null");
                    }
                }
            };
        }
Esempio n. 5
0
        public void Read(string filepath)
        {
            this._filename = filepath;

            string data = string.Empty;

            using (StreamReader reader = new StreamReader(filepath))
            {
                data = reader.ReadToEnd();
            }

            string[] settings = data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string thisSetting in settings)
            {
                string regex = "(?<type>.*)\\:(?<dtype>\\w)\\:(?<value>.*)";

                RegexOptions options =
                    ((RegexOptions.IgnorePatternWhitespace |
                      RegexOptions.Multiline) | RegexOptions.IgnoreCase);
                Regex reg = new Regex(regex, options);

                if (reg.IsMatch(thisSetting))
                {
                    Match m = reg.Match(thisSetting);

                    string v = m.Groups["value"].Value;

                    switch (m.Groups["type"].Value)
                    {
                    case "screen mode id":
                        this._screenMode = int.Parse(v);
                        break;

                    case "desktopwidth":
                        this._desktopWidth = int.Parse(v);
                        break;

                    case "desktopheight":
                        this._desktopHeight = int.Parse(v);
                        break;

                    case "session bpp":
                        this._sessionBPP = (SessionBPPs)int.Parse(v);
                        break;

                    case "winposstr":
                        string[] vals = v.Split(',');

                        this._winPosStr.WinState = (WindowState)int.Parse(vals[1]);

                        this._winPosStr.Rect.Top    = int.Parse(vals[2]);
                        this._winPosStr.Rect.Left   = int.Parse(vals[3]);
                        this._winPosStr.Rect.Width  = int.Parse(vals[4]);
                        this._winPosStr.Rect.Height = int.Parse(vals[5]);

                        break;

                    case "full address":
                        this._fullAddress = v;
                        break;

                    case "compression":
                        this._compression = int.Parse(v);
                        break;

                    case "keyboardhook":
                        this._keyboardHook = (KeyboardHooks)int.Parse(v);
                        break;

                    case "audiomode":
                        this._audiomode = (AudioModes)int.Parse(v);
                        break;

                    case "redirectdrives":
                        this._redirectDrives = int.Parse(v);
                        break;

                    case "redirectprinters":
                        this._redirectPrinters = int.Parse(v);
                        break;

                    case "redirectcomports":
                        this._redirectComPorts = int.Parse(v);
                        break;

                    case "redirectsmartcards":
                        this._redirectSmartCards = int.Parse(v);
                        break;

                    case "displayconnectionbar":
                        this._displayConnectionBar = int.Parse(v);
                        break;

                    case "autoreconnection enabled":
                        this._autoReconnectionEnabled = int.Parse(v);
                        break;

                    case "username":
                        this._username = v;
                        break;

                    case "domain":
                        this._domain = v;
                        break;

                    case "alternate shell":
                        this._alternateShell = v;
                        break;

                    case "shell working directory":
                        this._shellWorkingDirectory = v;
                        break;

                    case "password 51":
                        this._password = v;
                        break;

                    case "disable wallpaper":
                        this._disableWallpaper = int.Parse(v);
                        break;

                    case "disable full window drag":
                        this._disableFullWindowDrag = int.Parse(v);
                        break;

                    case "disable menu anims":
                        this._disableMenuAnims = int.Parse(v);
                        break;

                    case "disable themes":
                        this._disableThemes = int.Parse(v);
                        break;

                    case "disable cursor setting":
                        this._disableCursorSettings = int.Parse(v);
                        break;

                    case "bitmapcachepersistenable":
                        this._bitmapCachePersistEnable = int.Parse(v);
                        break;
                    }
                }
            }
        }
Esempio n. 6
0
        public void Read(string filepath)
        {
            this._filename = filepath;

            string data = string.Empty;

            using (StreamReader reader = new StreamReader(filepath))
            {
                data = reader.ReadToEnd();
            }

            string[] settings = data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string thisSetting in settings)
            {
                string regex = "(?<type>.*)\\:(?<dtype>\\w)\\:(?<value>.*)";
      
                RegexOptions options = 
                    ((RegexOptions.IgnorePatternWhitespace | 
                      RegexOptions.Multiline) | RegexOptions.IgnoreCase);
                Regex reg = new Regex(regex, options);

                if (reg.IsMatch(thisSetting))
                {
                    Match m = reg.Match(thisSetting);

                    string v = m.Groups["value"].Value;

                    switch (m.Groups["type"].Value)
                    {
                        case "screen mode id":
                            this._screenMode = int.Parse(v);
                            break;

                        case "desktopwidth":
                            this._desktopWidth = int.Parse(v);
                            break;

                        case "desktopheight":
                            this._desktopHeight = int.Parse(v);
                            break;

                        case "session bpp":
                            this._sessionBPP = (SessionBPPs)int.Parse(v);
                            break;

                        case "winposstr":
                            string[] vals = v.Split(',');

                            this._winPosStr.WinState = (WindowState)int.Parse(vals[1]);

                            this._winPosStr.Rect.Top = int.Parse(vals[2]);
                            this._winPosStr.Rect.Left = int.Parse(vals[3]);
                            this._winPosStr.Rect.Width = int.Parse(vals[4]);
                            this._winPosStr.Rect.Height = int.Parse(vals[5]);

                            break;

                        case "full address":
                            this._fullAddress = v;
                            break;
                  
                        case "compression":
                            this._compression = int.Parse(v);
                            break;

                        case "keyboardhook":
                            this._keyboardHook = (KeyboardHooks)int.Parse(v);
                            break;

                        case "audiomode":
                            this._audiomode = (AudioModes)int.Parse(v);
                            break;

                        case "redirectdrives":
                            this._redirectDrives = int.Parse(v);
                            break;

                        case "redirectprinters":
                            this._redirectPrinters = int.Parse(v);
                            break;

                        case "redirectcomports":
                            this._redirectComPorts = int.Parse(v);
                            break;

                        case "redirectsmartcards":
                            this._redirectSmartCards = int.Parse(v);
                            break;

                        case "displayconnectionbar":
                            this._displayConnectionBar = int.Parse(v);
                            break;

                        case "autoreconnection enabled":
                            this._autoReconnectionEnabled = int.Parse(v);
                            break;

                        case "username":
                            this._username = v;
                            break;

                        case "domain":
                            this._domain = v;
                            break;

                        case "alternate shell":
                            this._alternateShell = v;
                            break;

                        case "shell working directory":
                            this._shellWorkingDirectory = v;
                            break;

                        case "password 51":
                            this._password = v;
                            break;

                        case "disable wallpaper":
                            this._disableWallpaper = int.Parse(v);
                            break;

                        case "disable full window drag":
                            this._disableFullWindowDrag = int.Parse(v);
                            break;

                        case "disable menu anims":
                            this._disableMenuAnims = int.Parse(v);
                            break;

                        case "disable themes":
                            this._disableThemes = int.Parse(v);
                            break;

                        case "disable cursor setting":
                            this._disableCursorSettings = int.Parse(v);
                            break;

                        case "bitmapcachepersistenable":
                            this._bitmapCachePersistEnable = int.Parse(v);
                            break;
                    }
                }
            }
        }