public static bool ConfirmWriteToProtectedSectionOfRegistryOnVistaOrLater(string innerText) { string text = "In order to write " + innerText + ", Key Mapper needs to add to " + "the protected section of your computer's registry. You may need to approve this action " + "which will be performed by your Registry Editor."; TaskDialogResult result = FormsManager.ShowTaskDialog("Do you want to proceed?", text, "Key Mapper", TaskDialogButtons.Yes | TaskDialogButtons.No, TaskDialogIcon.SecurityShield); return(result == TaskDialogResult.Yes); }
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); }