コード例 #1
0
ファイル: MappingsManager.cs プロジェクト: xthxne/keymapper
        private static Collection <KeyMapping> GetMappingsFromScancodeMap(byte[] map, MappingType type)
        {
            // Transform the byte array into keymappings

            var maps = new Collection <KeyMapping>();

            int count  = 0;
            int length = map.GetLength(0);

            // How many mappings are there?
            // (Make sure there are at least 8 bytes in the array)

            if (length > 8)
            {
                count = map[8] - 1;
            }

            if (count == 0)
            {
                return(maps);
            }

            const int start = 12;

            for (int i = 0; i < count; i++)
            {
                // Make sure we don't extend beyond array bounds
                if (length >= (start + (i * 4) + 3))
                {
                    // First pair is the action - what the mapped key does.
                    int word1 = map[start + (i * 4)];
                    int word2 = map[start + (i * 4) + 1];

                    var tokey = new Key(word1, word2);

                    // Second pair is the physical key which performs the new action
                    word1 = map[start + (i * 4) + 2];
                    word2 = map[start + (i * 4) + 3];

                    var fromkey = new Key(word1, word2);

                    var mapping = new KeyMapping(fromkey, tokey);

                    if (mapping.IsValid())
                    {
                        mapping.SetType(type);
                        maps.Add(mapping);
                    }
                    else
                    // Just ignore it and hope it goes away.
                    // A manually added - or garbled - entry could be invalid.
                    {
                    }
                }
            }

            return(maps);
        }
コード例 #2
0
ファイル: MappingsManager.cs プロジェクト: stuartd/keymapper
        public static void DeleteMapping(KeyMapping map)
        {
            if (!map.IsValid())
                throw new ArgumentException("Can't delete an invalid map");
            PushMappingsOntoUndoStack();

            if (mappings.Contains(map))
            {
                mappings.Remove(map);
            }

            RaiseMappingsChangedEvent();
        }
コード例 #3
0
        public static void DeleteMapping(KeyMapping map)
        {
            if (!map.IsValid())
            {
                throw new ArgumentException("Can't delete an invalid map");
            }
            PushMappingsOntoUndoStack();

            if (mappings.Contains(map))
            {
                mappings.Remove(map);
            }

            RaiseMappingsChangedEvent();
        }
コード例 #4
0
ファイル: MappingsManager.cs プロジェクト: xthxne/keymapper
        public static void DeleteMapping(KeyMapping map, MappingFilter filter)
        {
            if (!map.IsValid())
            {
                throw new ArgumentException("Can't delete an invalid map");
            }

            PushMappingsOntoUndoStack();

            switch (filter)
            {
            case MappingFilter.All:
                // Could be mapped in both HKCU and HKLM so
                // remove the HKCU mapping first, but not both..

                if (_userMappings.Contains(map))
                {
                    _userMappings.Remove(map);
                }
                else if (_bootMappings.Contains(map))
                {
                    _bootMappings.Remove(map);
                }
                break;

            case MappingFilter.Boot:
                if (_bootMappings.Contains(map))
                {
                    _bootMappings.Remove(map);
                }
                break;

            case MappingFilter.User:
                if (_userMappings.Contains(map))
                {
                    _userMappings.Remove(map);
                }
                break;

            default:
                break;
            }

            RaiseMappingsChangedEvent();
        }
コード例 #5
0
ファイル: MappingsManager.cs プロジェクト: stuartd/keymapper
        private static Collection<KeyMapping> GetMappingsFromScancodeMap(byte[] map)
        {
            // Transform the byte array into keymappings
            var maps = new Collection<KeyMapping>();

            int count = 0;
            int length = map.GetLength(0);

            // How many mappings are there?
            // (Make sure there are at least 8 bytes in the array)

            if (length > 8)
                count = map[8] - 1;

            if (count == 0)
            {
                return maps;
            }

            const int start = 12;

            for (int i = 0; i < count; i++)
            {
                // Make sure we don't extend beyond array bounds
                if (length >= (start + (i * 4) + 3))
                {
                    // First pair is the action - what the mapped key does.
                    int word1 = map[start + (i * 4)];
                    int word2 = map[start + (i * 4) + 1];

                    var tokey = new Key(word1, word2);

                    // Second pair is the physical key which performs the new action
                    word1 = map[start + (i * 4) + 2];
                    word2 = map[start + (i * 4) + 3];

                    var fromkey = new Key(word1, word2);

                    var mapping = new KeyMapping(fromkey, tokey);

                    if (mapping.IsValid())
                    {
                        maps.Add(mapping);
                    }
                    else
                    // Just ignore it and hope it goes away.
                    // A manually added - or garbled - entry could be invalid.
                    {
                    }
                }
            }

            return maps;
        }
コード例 #6
0
ファイル: MappingsManager.cs プロジェクト: stuartd/keymapper
        private static bool AddMapping(KeyMapping map, bool noStackNoEventRaised)
        {
            if (!map.IsValid())
            {
                return false;
            }

            int scancode = map.From.Scancode;
            int extended = map.From.Extended;

            // If user is remapping Left Ctrl, Left Alt, or Delete then s/he must confirm
            // that it could be goodbye to CTRL-ALT-DEL

            if ((scancode == 29 && extended == 0) || (scancode == 56 && extended == 0) ||
                (scancode == 83 && extended == 224))
            {
                string action = IsDisabledMapping(map) ? "disable " : "remap ";

                string warning = "You are attempting to " + action + map.From.Name +
                                 " which is required for CTRL-ALT-DELETE." + (char)13 +
                                 "If you continue you may not be able to log on" +
                                 " to your PC.";

                string question = "Are you really sure you want to " + action + "this key?";

                TaskDialogResult dr = FormsManager.ShowTaskDialog(question, warning, "Key Mapper",
                                                                  TaskDialogButtons.Yes | TaskDialogButtons.No,
                                                                  TaskDialogIcon.Question);
                if (dr != TaskDialogResult.Yes)
                    return false;

            }

            // If user is remapping Pause, then suggest they will want to disable Num Lock as well.

            bool disableNumLock = false;

            if (scancode == 29 && extended == 225 && IsDisabledMapping(map) == false)
            {
                // Is Num Lock already disabled or remapped?
                bool numLockIsDisabled = false;
                bool numLockIsMapped = false;

                foreach (KeyMapping km in mappings)
                    if (km.From.Scancode == 69)
                    {
                        if (IsDisabledMapping(km))
                            numLockIsDisabled = true;
                        else
                            numLockIsMapped = true;
                    }

                if (numLockIsDisabled == false)
                {
                    string warning = "If you remap Pause, the Num Lock key will be disabled" +
                                     (numLockIsMapped
                                          ? ((char)13 + "and your existing Num Lock mapping will be removed.")
                                          : ".");

                    const string question = "Do you still want to remap Pause?";

                    TaskDialogResult dr = FormsManager.ShowTaskDialog(question, warning, "Key Mapper",
                                                                      TaskDialogButtons.Yes | TaskDialogButtons.No,
                                                                      TaskDialogIcon.Question);
                    if (dr != TaskDialogResult.Yes)
                        return false;

                    disableNumLock = true;
                }
            }

            if (noStackNoEventRaised == false)
                PushMappingsOntoUndoStack();

            // Check for any existing mappings for this key
            // if they exist, this mapping needs to replace them.

            KeyMapping existingMap = GetKeyMapping(map.From.Scancode, map.From.Extended);

            if (existingMap.IsEmpty() == false)
                mappings.Remove(existingMap);

            mappings.Add(map);

            if (disableNumLock)
            {
                var nl = new KeyMapping(new Key(69, 0), new Key(0, 0));
                AddMapping(nl, true);
            }

            if (noStackNoEventRaised == false)
                RaiseMappingsChangedEvent();

            return true;
        }
コード例 #7
0
        private static bool AddMapping(KeyMapping map, bool noStackNoEventRaised)
        {
            if (!map.IsValid())
            {
                return(false);
            }

            int scancode = map.From.Scancode;
            int extended = map.From.Extended;

            // If user is remapping Left Ctrl, Left Alt, or Delete then s/he must confirm
            // that it could be goodbye to CTRL-ALT-DEL

            if ((scancode == 29 && extended == 0) || (scancode == 56 && extended == 0) ||
                (scancode == 83 && extended == 224))
            {
                string action = IsDisabledMapping(map) ? "disable " : "remap ";

                string warning = "You are attempting to " + action + map.From.Name +
                                 " which is required for CTRL-ALT-DELETE." + (char)13 +
                                 "If you continue you may not be able to log on" +
                                 " to your PC.";

                string question = "Are you really sure you want to " + action + "this key?";


                TaskDialogResult dr = FormsManager.ShowTaskDialog(question, warning, "Key Mapper",
                                                                  TaskDialogButtons.Yes | TaskDialogButtons.No,
                                                                  TaskDialogIcon.Question);
                if (dr != TaskDialogResult.Yes)
                {
                    return(false);
                }
            }

            // If user is remapping Pause, then suggest they will want to disable Num Lock as well.

            bool disableNumLock = false;

            if (scancode == 29 && extended == 225 && IsDisabledMapping(map) == false)
            {
                // Is Num Lock already disabled or remapped?
                bool numLockIsDisabled = false;
                bool numLockIsMapped   = false;

                foreach (KeyMapping km in mappings)
                {
                    if (km.From.Scancode == 69)
                    {
                        if (IsDisabledMapping(km))
                        {
                            numLockIsDisabled = true;
                        }
                        else
                        {
                            numLockIsMapped = true;
                        }
                    }
                }

                if (numLockIsDisabled == false)
                {
                    string warning = "If you remap Pause, the Num Lock key will be disabled" +
                                     (numLockIsMapped
                                          ? ((char)13 + "and your existing Num Lock mapping will be removed.")
                                          : ".");

                    const string question = "Do you still want to remap Pause?";


                    TaskDialogResult dr = FormsManager.ShowTaskDialog(question, warning, "Key Mapper",
                                                                      TaskDialogButtons.Yes | TaskDialogButtons.No,
                                                                      TaskDialogIcon.Question);
                    if (dr != TaskDialogResult.Yes)
                    {
                        return(false);
                    }

                    disableNumLock = true;
                }
            }

            if (noStackNoEventRaised == false)
            {
                PushMappingsOntoUndoStack();
            }

            // Check for any existing mappings for this key
            // if they exist, this mapping needs to replace them.

            KeyMapping existingMap = GetKeyMapping(map.From.Scancode, map.From.Extended);

            if (existingMap.IsEmpty() == false)
            {
                mappings.Remove(existingMap);
            }

            mappings.Add(map);

            if (disableNumLock)
            {
                var nl = new KeyMapping(new Key(69, 0), new Key(0, 0));
                AddMapping(nl, true);
            }

            if (noStackNoEventRaised == false)
            {
                RaiseMappingsChangedEvent();
            }

            return(true);
        }
コード例 #8
0
ファイル: AddEditMapping.cs プロジェクト: stuartd/keymapper
        public AddEditMapping(KeyMapping map, bool useCapture)
        {
            InitializeComponent();

            // There are four startup states for this form.

            // 1) Choose a From key by capturing it
            // 2) Choose a mapping for a specific From key
            // 3) Display a given mapping From and To. Includes disabled.
            // 4) Select a From key from the lists

            // Map is a struct so it can't be null.
            if (map.IsEmpty())
            {
                if (useCapture)
                {
                    // We are capturing the 'from' key.
                    capturingFromKey = true;
                }
                else
                {
                    selectingFromKeyFromLists = true;
                }
            }
            else
            {
                mapped = (map.To.Scancode > 0);
                disabled = (map.To.Scancode == 0);
            }

            newMapping = !map.IsValid();

            this.map = map;

            // Default has the KeyLists panel in the frame.
            if (mapped | disabled)
            {
                SwopPanelPositions(KeyListsPanel, MappingPanel);
            }
            else if (capturingFromKey)
            {
                SwopPanelPositions(EmptyPanel, KeyListsPanel);
            }

            if (selectingFromKeyFromLists)
            {
                // Need to move the lists to the left where the box while remembering where it was
                savedPanelLocation = KeyListsPanel.Location;
                KeyListsPanel.Left = FromKeyPictureBox.Left;
                keyThreshold = -1; // Show all keys as possible map-ees
            }
            else
                keyThreshold = 1;

            SetListOptionsComboIndex();

            PopulateKeyLists();

            // Add event handlers now values have been assigned
            GroupsListbox.SelectedIndexChanged += GroupsListboxSelectedIndexChanged;
            KeysByGroupListbox.SelectedIndexChanged += KeysByGroupListboxSelectedIndexChanged;
            ListOptionsCombo.SelectedIndexChanged += ListOptionsComboSelectedIndexChanged;
            KeysByGroupListbox.DoubleClick += KeysByGroupListboxDoubleClick;

            SetupForm();
        }
コード例 #9
0
ファイル: MappingsManager.cs プロジェクト: tmzu/keymapper
        public static void DeleteMapping(KeyMapping map, MappingFilter filter)
        {
            if (!map.IsValid())
                throw new ArgumentException("Can't delete an invalid map");

            PushMappingsOntoUndoStack();

            switch (filter)
            {
                case MappingFilter.All:
                    // Could be mapped in both HKCU and HKLM so 
                    // remove the HKCU mapping first, but not both..

                    if (_userMappings.Contains(map))
                    {
                        _userMappings.Remove(map);
                    }
                    else if (_bootMappings.Contains(map))
                    {
                        _bootMappings.Remove(map);
                    }
                    break;

                case MappingFilter.Boot:
                    if (_bootMappings.Contains(map))
                    {
                        _bootMappings.Remove(map);
                    }
                    break;

                case MappingFilter.User:
                    if (_userMappings.Contains(map))
                    {
                        _userMappings.Remove(map);
                    }
                    break;
                default:
                    break;
            }

            RaiseMappingsChangedEvent();
        }