示例#1
0
        public void PrintKeyDebug(Int32 key, Modifiers mod, bool isKeyDown)
        {
            KeyCommand command    = new KeyCommand();
            string     winKeyStr  = "0x" + key.ToString("x2");
            string     commandStr = winKeyStr;

            if (this.winKeyMapping.ContainsValue(winKeyStr))
            {
                string macKeyStr = this.winKeyMapping.FirstOrDefault(x => x.Value == winKeyStr).Key;
                KeyControl.TraceLine(string.Format(winKeyStr + " : " + macKeyStr));

                command.key = int.Parse(macKeyStr);
                command.mod = mod;

                commandStr = this.GetCommandStringForCommand(command);
            }

            if (isKeyDown)
            {
                KeyControl.TraceLine(string.Format("Key Down: {0}", commandStr));
            }
            else
            {
                KeyControl.TraceLine(string.Format("Key Up: {0}", commandStr));
            }
        }
示例#2
0
        public void LoadDictionaryFromActiveKeysFile()
        {
            this.isKeyControlActive = false;

            List <KeyCommand> keys = this.keyfileList[this.activeKeyfile].keys;

            // convert the settings into windows data
            this.keysDict = new List <KeyCommand>(keys.Count);
            foreach (KeyCommand command in keys)
            {
                KeyCommand newCommand = (KeyCommand)command.Clone();
                newCommand.key = this.TranslateKey(newCommand.key);
                this.keysDict.Add(newCommand);
            }

            this.controlToggleKey = this.TranslateKey(this.keyfileList[this.activeKeyfile].modeKey);
        }
示例#3
0
        private Keyfile GetLatestVersion(string contents)
        {
            Keyfile keyfile = this.jsSerializer.Deserialize <Keyfile>(contents);

            foreach (var key in keyfile.keys)
            {
                if (key.adj.ContainsKey(Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME))
                {
                    string    remapKey = key.adj[Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME] as string;
                    Modifiers remapMod = Modifiers.None;

                    if (remapKey == null)
                    {
                        Dictionary <string, object> remapDict = key.adj[Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME] as Dictionary <string, object>;

                        if (remapDict != null)
                        {
                            remapKey = (string)remapDict[Constants.KEYFILE_KEY_NODENAME];
                            remapMod = (Modifiers)int.Parse((string)remapDict[Constants.KEYFILE_MODIFIERS_NODENAME]);

                            if ((remapMod & Modifiers.Windows) == Modifiers.Windows)
                            {
                                remapMod |= Modifiers.Control;
                                remapMod ^= Modifiers.Windows;
                            }
                        }
                    }

                    KeyCommand cmd = new KeyCommand();
                    cmd.mod = remapMod;
                    cmd.key = int.Parse(remapKey);
                    cmd.adj = null;
                    key.adj[Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME] = cmd;
                }
            }

            return(keyfile);
        }
示例#4
0
        public string GetCommandStringForCommand(KeyCommand command)
        {
            StringBuilder sb = new StringBuilder();

            if ((command.mod & Modifiers.Shift) == Modifiers.Shift)
            {
                sb.Append("SHIFT + ");
            }

            if ((command.mod & Modifiers.Control) == Modifiers.Control)
            {
                sb.Append("CONTROL + ");
            }

            if ((command.mod & Modifiers.Alt) == Modifiers.Alt)
            {
                sb.Append("ALT + ");
            }

            if ((command.mod & Modifiers.Windows) == Modifiers.Windows)
            {
                sb.Append("WINDOWS + ");
            }

            string keyname = this.keyMapping[command.key.ToString()];

            if (!string.IsNullOrEmpty(keyname))
            {
                sb.Append(keyname);
            }
            else
            {
                sb.Append("?");
            }

            return(sb.ToString());
        }
示例#5
0
        private IntPtr HookCallBack(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
        {
            this.StartTiming();

            int  keyState  = (int)wParam;
            bool isKeyUp   = keyState == Constants.WM_KEYUP || (keyState == Constants.WM_SYSKEYUP);
            bool isKeyDown = keyState == Constants.WM_KEYDOWN || (keyState == Constants.WM_SYSKEYDOWN);

            // MSDN documentation indicates that nCodes less than 0 should always invoke CallNextHookEx.
            //  skip if the message is not a keyup or down
            if (nCode < 0 || !(isKeyUp || isKeyDown))
            {
                this.EndTiming("code 0");
                return(KeyControl.CallNextHookEx(this.hookID, nCode, wParam, ref lParam));
            }

            Int32     key       = lParam.vkCode;
            Modifiers modifiers = this.GetModifiers();

            // capture windows key
            if (key == Constants.VK_LWIN)
            {
                this.isLWinKeyDown = isKeyDown;
            }

            if (key == Constants.VK_RWIN)
            {
                this.isRWinKeyDown = isKeyDown;
            }

            // disable if we are active
            if (key == Constants.VK_LWIN || key == Constants.VK_RWIN)
            {
                if (this.CheckIsKeySystemEngaged())
                {
                    this.EndTiming("WIN key");
                    return(new IntPtr(1));
                }
            }

            // pass through keys that were remapped by the application
            if (this.IsSentKey(key, isKeyDown))
            {
                this.EndTiming("Sent key");
                return(KeyControl.CallNextHookEx(this.hookID, nCode, wParam, ref lParam));
            }

            // capture and pass through straight modifier keys
            if (this.GetIsModifierKey(key))
            {
                this.EndTiming("Straight mod");
                return(KeyControl.CallNextHookEx(this.hookID, nCode, wParam, ref lParam));
            }

            //this.PrintKeyDebug(key, modifiers, isKeyDown);

            // mode switch for app
            if (this.authSuccess && modifiers == Modifiers.None && key == this.controlToggleKey && this.CheckIsLRInForeground())
            {
                if (isKeyDown)
                {
                    this.ToggleKeyControlActive();
                }

                this.EndTiming("Mode switch");
                return(new IntPtr(1));
            }

            // show/hide quick keylist ( CONTROL + / )
            if (this.isKeyControlActive && (modifiers & Modifiers.Control) == Modifiers.Control && key == 0xbf)
            {
                if (isKeyUp)
                {
                    if (this.CheckIsKeySystemEngaged())
                    {
                        this.ShowQuickList();
                    }
                    else
                    {
                        this.DismissQuickList();
                    }
                }

                this.EndTiming("Quick Ref");
                return(new IntPtr(1));
            }

            if (this.CheckIsKeySystemEngaged())
            {
                if (this.keysDict != null)
                {
                    foreach (KeyCommand command in this.keysDict)
                    {
                        if (key == command.key && modifiers == command.mod)
                        {
                            if (command.adj.ContainsKey(Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME))
                            {
                                KeyCommand newKey = command.adj[Constants.KEYFILE_ADJUSTMENT_REMAP_NODENAME] as KeyCommand;

                                if (newKey == null)
                                {
                                    KeyControl.TraceLine(string.Format("Failed to map {0} {2} to {1}", key, this.TranslateKey(newKey.key), (isKeyDown) ? "Down" : "Up"));
                                    this.EndTiming("Remap failed");
                                    return(new IntPtr(1));
                                }

                                KeyControl.TraceLine(string.Format("Mapping {0} {2} to {1}", key, this.GetCommandStringForCommand(newKey), (isKeyDown) ? "Down" : "Up"));

                                this.EndTiming("Remap");

                                this.SendModifiers(modifiers, false);

                                this.SendModifiers(newKey.mod, true);

                                this.SendKey(this.TranslateKey(newKey.key), isKeyDown);

                                this.SendModifiers(newKey.mod, false);

                                this.SendModifiers(modifiers, true);

                                return(new IntPtr(1));
                            }

                            if (isKeyDown)
                            {
                                if (command.adj != null && command.adj.Count > 0)
                                {
                                    Dictionary <string, string> adjustments = command.adj.ToDictionary((o) => o.Key, (o) => (string)o.Value);
                                    KeyControl.TraceLine("Key Command Executed");
                                    this.statusBar.Dispatcher.BeginInvoke(this.sendUpdateDelegate, adjustments);
                                }
                            }

                            this.EndTiming("Key command");
                            return(new IntPtr(1));
                        }
                    }
                }
            }

            this.EndTiming("Pass through");
            return(KeyControl.CallNextHookEx(this.hookID, nCode, wParam, ref lParam));
        }