Skip to content

Commit

Permalink
Add "Clear Remap" to right-click menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashraf Hadden committed Jan 12, 2019
1 parent 6339765 commit c37da2f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
56 changes: 36 additions & 20 deletions CampKeys.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@ SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

; Windows Shortcut Docs: https://support.microsoft.com/en-us/help/12445/windows-keyboard-shortcuts

;; Tray Icon & Tip
; Menu, Tray, Icon, CampKeys.ico ; Commented out to prevent "Error: Can't load icon", requires pre-compile removal
Menu, Tray, Tip, CampKeys

;; Reload Script on Left-Click Tray Icon
OnMessage(0x404, "AHK_NOTIFYICON")
AHK_NOTIFYICON(wParam, lParam, uMsg, hWnd)
{
if (lParam = 0x201) { ;WM_LBUTTONDOWN := 0x201
Reload
}
}

;; Admin Priveleges
; https://autohotkey.com/docs/commands/Run.htm#RunAs
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
try {
if A_IsCompiled {
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try
{
if A_IsCompiled
{
Run *RunAs "%A_ScriptFullPath%" /restart
}
else {
Expand All @@ -28,23 +38,29 @@ if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
ExitApp
}

;; Reload Script on Left-Click Tray Icon
OnMessage(0x404, "AHK_NOTIFYICON")
AHK_NOTIFYICON(wParam, lParam, uMsg, hWnd) {
if (lParam = 0x201) { ;WM_LBUTTONDOWN := 0x201
Reload
}
;; Remap LCmd w/ RCtrl in Registry
RegRead, Remap_LCmdRCtrl, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map
If Remap_LCmdRCtrl != 0000000000000000020000001de05be000000000
{
RegWrite, REG_BINARY, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map, 0000000000000000020000001de05be000000000
MsgBox Logout for key remap, Please logout or restart your computer in order for the key remap (LCmd to RCtrl) to take effect.`nThis is necessary for CampKeys to function properly.
TrayTip Logout for key remap, Please logout or restart your computer in order for the key remap (LCmd to RCtrl) to take effect.`nThis is necessary for CampKeys to function properly.,, 1
}

;; Remap LCmd w/ RCtrl in Registry
RegRead, Remap_LCmd_RCtrl, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map
If Remap_LCmd_RCtrl = 0000000000000000020000001de05be000000000
return
Else
RegWrite, Reg_Binary, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map, 0000000000000000020000001de05be000000000
TrayTip Logout for key remap, Please logout or restart your computer in order for the key remap (LCmd to RCtrl) to take effect,, 1

; #Include CampKeys_GUI.ahk
Menu, Tray, Tip, CampKeys
Menu, Tray, Add, Clear Remap, Clear_Remap
return

Clear_Remap:
{
MsgBox, 1, Clear Remap, Clearing remap (LCmd to RCtrl), continue?
IfMsgBox, Cancel
{
return
}
RegDelete, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map
MsgBox CampKeys succesfully uninstalled! Please logout or restart for the key remap (LCmd to Rctrl) to reset.
}

;;───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
;; Mac keyboard shortcuts
Expand Down
14 changes: 7 additions & 7 deletions CampKeys_GUI.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Gui Font, q5 s9, Roboto
Gui Add, Tab3,, General|App-Specific|Extras|Custom
;; General Tab
Gui Add, GroupBox, Section, Remap
RegRead, SwapCmdCtrl, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map
If SwapCmdCtrl = 0000000000000000020000001de05be000000000
RegRead, Remap_LCmdRCtrl, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map
If Remap_LCmdRCtrl = 0000000000000000020000001de05be000000000
Checktype := "Checked1"
Else
Checktype := "Checked0"
Expand Down Expand Up @@ -51,16 +51,16 @@ return
GuiClose:
GuiEscape:
Gui, Submit ; Save each control's contents to its associated variable.
; MsgBox SwapCmdCtrlSetting: %SwapCmdCtrlSetting% SwapCmdCtrl: %SwapCmdCtrl%
; MsgBox Remap_LCmdRCtrlSetting: %Remap_LCmdRCtrlSetting% Remap_LCmdRCtrl: %Remap_LCmdRCtrl%

If (SwapCmdCtrlSetting = 1 && SwapCmdCtrl = "")
If (Remap_LCmdRCtrlSetting = 1 && Remap_LCmdRCtrl = "")
{
RegWrite, REG_BINARY, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map, 0000000000000000020000001de05be000000000
TrayTip, CampKeys, You've made a system level key remap! Please logout or restart for changes to take affect.
TrayTip, CampKeys, You've made a system level key Remap_! Please logout or restart for changes to take affect.
}

If (SwapCmdCtrlSetting = 0 AND SwapCmdCtrl = "0000000000000000020000001de05be000000000")
If (Remap_LCmdRCtrlSetting = 0 AND Remap_LCmdRCtrl = "0000000000000000020000001de05be000000000")
{
RegDelete, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layout, Scancode Map
TrayTip, CampKeys, You've made a system level key remap! Please logout or restart for changes to take affect.
TrayTip, CampKeys, You've made a system level key Remap_! Please logout or restart for changes to take affect.
}

0 comments on commit c37da2f

Please # to comment.