Repository: m2nlight/AHKShortcutLikeMac
Branch: master
Commit: 780c3fe279ca
Files: 4
Total size: 38.2 KB
Directory structure:
gitextract_nnsrz824/
├── LICENSE
├── README.md
├── machotkey.ahk
└── register_schedule_task.bat
================================================
FILE CONTENTS
================================================
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2018 m2nlight
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# AHKShortcutLikeMac
An AHK Script for using keyboard shortcuts like MacOS on your Windows
About **AutoHotKey** [_HomePage_](https://www.autohotkey.com/) [_Github_](https://github.com/Lexikos/AutoHotkey_L/)
```txt
AutoHotKey v2 is alpha-release. Suggest use v1.1.*
```
v1.1.33.02 downloads
* [AutoHotkey Portable](https://www.autohotkey.com/download/1.1/AutoHotkey_1.1.33.02.zip)
Script Features:
* Hot string (e.g. `]date`, `]time`, `]now`, `]longdate`)
* Shortcuts table:
| HotKeys | Desc |
| -------------------------------------------------------------------------------------- | ------------------------------------------------- |
| _MacOS shortcuts_ | |
| Win ` | Active next same class window |
| Win H | Hide(minimize) current window |
| Win Alt H | Hide(minimize) other windows |
| Win M | Hide(minimize) current windows |
| Win Alt M | Hide(minimize) all windows |
| Win Q | Quit current application |
| Win T | New tab (Ctrl+T) |
| Win Shift T | Reload last tab (Ctrl+Shift+T) |
| Win N | New... |
| Win O | Open... |
| Win W | Close the table |
| Win S | Save |
| Win P | Print (Ctrl+P) |
| Win Z | Undo |
| Win Shift Z | Redo |
| Win X | Cut |
| Win C | Copy |
| Win V | Paste |
| Win Alt V | Move files from clipboard to current location |
| Win Shift Alt V | Paste as text |
| Win A | Select all |
| Win F | Find (Ctrl+F) |
| Win G | Find (F3) |
| Win Shift G | Find previous (Shift+F3) |
| Win Alt F | Replace (Ctrl+H) |
| Win Left or Right or Up or Down | (Home/End/PgUp/PgDown) |
| Alt Left or Right | (Ctrl+Left/Right) |
| Win Alt F | Full screen (F11) |
| Win = | Zoom in |
| Win - | Zoom out |
| Win 0 | Resize zoom (Ctrl+0) |
| Win R | Refresh |
| Win Backspace | Delete |
| Win Shift 3 | Capture screen to clipboard |
| Win Shift 4 | Capture screen with region (Win10) |
| Win Shift 5 | Start Snipping Tool (Win10) |
| Win F3 | Show desktop |
| Win I | Show file/folder property dialog (Alt+Enter) |
| Win F10 | Mute |
| Win F11 | Volume down |
| Win F12 | Volume up |
| Win Shift Backspace | Empty Recycle Bin |
| Win Shift Alt Backspace | Empty Recycle Bin without prompt |
| Win Alt Esc | Run task manager |
| Win Shift Alt Esc | Kill current process |
| Win Shift Alt Ctrl Esc | Kill all image name processes |
| __Explorer shortcuts__ | |
| Win Enter | Rename (F2) |
| Win O | Open (Enter) |
| Win Up | Up to |
| Win Down | Open (Enter) same to `Win+O` |
| Win Shift N | New folder | |
| Win Shift . | Show or hide hidden files | |
| _CapsLock+ shortcuts_ | |
| CapsLock Space | `Ctrl+Space` |
| CapsLock Backspace | Delete to line head |
| CapsLock Delete | Delete to line end |
| CapsLock Enter | New line |
| CapsLock RShift | Line split |
| CapsLock D | Duplicate line |
| CapsLock W | Selected current line |
| CapsLock C or X or V | Copy/Cut/PasteAt current line |
| CapsLock Insert | Paste as text |
| CapsLock Alt/Shift 8 | Input a random password |
| CapsLock (Shift) B | Move left |
| CapsLock (Shift) F | Move right |
| CapsLock (Shift) P | Move up |
| CapsLock (Shift) N | Move down |
| CapsLock (Shift) A | Move line start |
| CapsLock (Shift) E | Move line end |
| CapsLock `1234567890 | Set current window transparent to 0% ~ 100% |
| _LAlt+ shortcuts_ | _LAlt means left alt key_ |
| LAlt C or X | Copy/Cut to line end |
| LAlt V | paste and go/enter |
| _Function Key_ | |
| CapsLock Esc | Homepage |
| CapsLock F1 | Show Help |
| CapsLock F2 | Toggle current window to topmost |
| CapsLock Alt/Shift F2 | Turn off/on current window to topmost |
| CapsLock F3 | Run Listary |
| CapsLock (Shift) F4 | Run Everything (as administrator) |
| CapsLock F5 | Run pageant ([PuTTY][1]) |
| CapsLock F6 | Run puttygen ([PuTTY][1]) |
| CapsLock (Shift) F7 | Run psftp (as administrator) ([PuTTY][1]) |
| CapsLock F8 | Run putty ([PuTTY][1]) |
| CapsLock (Shift) F9 | Windows Terminal or PowerShell (as administrator) |
| CapsLock (Shift) F10 | CMD (as administrator) |
| CapsLock F11 | Bash (Win10 WSL) |
| CapsLock (Shift) F12 | [Git-bash][2] (as administrator) |
| _Special Key_ | |
| Win F1 | Show Windows WinX Menus |
| Win F2 | Show Windows run dialog |
| Win F3 | Show Desktop |
| Win F10 | Mute |
| Win F11 | Volume down |
| Win F12 | Volume up |
| and more... | |
[1]: https://www.chiark.greenend.org.uk/~sgtatham/putty/
[2]: http://www.git-scm.com/download/win
Thanks:
* [@g1084164986](https://github.com/g1084164986) - Mouse direction support.
* [@liuyukuan](http://blog.csdn.net/liuyukuan/article/details/53885184) - Explorer rename support by his `ActiveControlIsOfClass` code.
Tips:
* Auto run when logon: You can complied it to an execute file by **Ahk2Exe**, then create a shortcut file into Startup Menu(Win10: `%appdata%\Microsoft\Windows\Start Menu\Programs\Startup`)
or create a schedule task:
Copy `register_schedule_task.bat` with `machotkey.exe` in a folder, then run
```cmd
register_schedule_task.bat
```
* Shortcuts mapping at Virtual Machine (XP~win10) on mac.
* [QuickLook](https://github.com/xupefei/QuickLook) is alike MacOS Quick-Look tool, press Space to preview some file in the Explorer.
* Switch Win and Alt by registry (win7 ~ win10):
```ini
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,05,00,00,00,5b,e0,38,00,38,00,5b,e0,\
5c,e0,38,e0,38,e0,5c,e0,00,00,00,00
```
Restore key switch:
```ini
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Keyboard Layout]
"Scancode Map"=-
```
A GUI tool name is [sharpkeys](https://github.com/randyrants/sharpkeys) can do this.
================================================
FILE: machotkey.ahk
================================================
; Shortcuts like mac
; Written by m2nlight
; https://github.com/m2nlight/AHKShortcutLikeMac
#SingleInstance Off
#HotkeyInterval 2000
#HotkeyModifierTimeout 100
SetWorkingDir, %A_ScriptDir%
global my_name := "MacHotKey"
global my_version := "v0.3.1"
global my_bit := A_PtrSize * 8
global my_website := "https://github.com/m2nlight/AHKShortcutLikeMac"
if A_Args.Length() > 0 {
#NoEnv
#Persistent
try {
cmd := A_Args[1]
if (cmd = "movefiles") {
ShellMoveFile()
} else if (cmd = "emptybin") {
EmptyBin()
} else if (cmd = "silentemptybin") {
EmptyBin(true)
} else if (cmd = "SwitchHiddenFiles") {
SwitchHiddenFiles()
Send {F5}
} else if (cmd = "help" or cmd = "version") {
ShowHelp()
} else {
ExitApp, 1
}
}
ExitApp
}
; ## Special Key ##
#F1::Send #x ; Show WinX menu in win10
#F2::Send #r ; Show run dialog
#`::NextWindow()
; ## Menu ##
#H::WinMinimize, A
!#H::HideOtherWindow()
#M::WinMinimize, A
!#M::WinMinimizeAll
#Q::Send !{F4}
; File
#T::Send ^t
+#T::Send +^t
#N::Send ^n
+#N::Send +^n
#O::Send ^o
#W::Send ^w
#+W::Send #w
#S::Send ^s
#P::Send ^p
#+P::Send #p
; Edit
#Z::Send ^z
+#Z::Send ^y
#X::Send ^x
#C::Send ^c
#V::Send ^v
!+#V::
clipboard = %clipboard%
Send ^v
return
#A::Send ^a
#F::Send ^f
#G::Send {F3}
+#G::Send +{F3}
!#F::Send ^h
#Left::Send {Home}
#Right::Send {End}
#Up::Send {PgUp}
#Down::Send {PgDn}
0) {
last := pExp.LocationURL
}
}
}
}
if(getLastWhenNoFound and last) {
return last
}
}
ConvertExplorerURLToPath(url)
{
If !url
Return ""
path := url
path := RegExReplace(path, "ftp://.*@","ftp://")
StringReplace, path, path, file:///
StringReplace, path, path, /, \, All
Loop
If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
Else Break
Return path
}
ActiveControlIs(Control) {
ControlGetFocus, FocusedControl, A
return (FocusedControl=Control)
}
ActiveControlIsOfClass(Class) {
ControlGetFocus, FocusedControl, A
ControlGet, FocusedControlHwnd, Hwnd,, %FocusedControl%, A
WinGetClass, FocusedControlClass, ahk_id %FocusedControlHwnd%
return (FocusedControlClass=Class)
}
GeneratePassword(length, withSpecialChars=false) {
Characters = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
if withSpecialChars {
Characters .= "``~!@#$`%^&*()_+-=[]{}\|`;:'""`,.<>/?"
}
Loop %length% {
Random, r, 1, % StrLen(Characters)
Passwords .= SubStr(Characters, r, 1)
}
SendInput {Raw}%Passwords%
}
SetTransparent(value) {
if (value is not integer) {
return
}
if (value >= 100 or value < 0) {
WinSet, Transparent, 255, A
return
}
value := value*255//100
WinSet, Transparent, %value%, A
}
RunNewInstance(cmd, runAsAdmin = false) {
If A_IsCompiled {
if (runAsAdmin && not A_IsAdmin) {
try {
Run *RunAs %A_ScriptFullPath% %cmd%
}
return
}
Run %A_ScriptFullPath% %cmd%
return
}
if (runAsAdmin && not A_IsAdmin) {
try {
Run *RunAs %A_AhkPath% %A_ScriptFullPath% %cmd%
}
return
}
Run %A_AhkPath% %A_ScriptFullPath% %cmd%
}
SwitchHiddenFiles() {
SetRegView %my_bit%
try {
RegRead, OutputVar, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden
}
catch {
OutputVar = 0
}
if (OutputVar and OutputVar = 1) {
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2
} else {
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 1
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
}
}
CheckMoveFile() {
target_dir := RealCurrentPath()
if StrLen(target_dir) = 0 {
return false
}
source_files := ""
Loop, parse, clipboard, `n, `r
{
IfNotExist, %A_LoopField%, continue
source_files = %source_files%%A_LoopField%|
}
if StrLen(source_files) = 0 {
return false
}
return true
}
ShellMoveFile() {
target_dir := RealCurrentPath()
if StrLen(target_dir) = 0 {
return
}
; fix network path "file://ipaddress/path" to "\\ipaddress\path"
StringReplace, target_dir, target_dir, file:, , All
StringReplace, target_dir, target_dir, /, \, All
source_files := ""
Loop, parse, clipboard, `n, `r
{
IfNotExist, %A_LoopField%, continue
source_files = %source_files%%A_LoopField%|
}
if StrLen(source_files) = 0 {
return
}
;msgbox Will to move %source_files% to %target_dir%
ShellFileOperation("FO_MOVE", source_files, target_dir,"FOF_ALLOWUNDO|FOF_SIMPLEPROGRESS|FOF_NOCONFIRMMKDIR")
}
; https://autohotkey.com/board/topic/51486-shellfileoperation-library/
; https://github.com/7plus/7plus/blob/f3b270f7b182d2ad023efb00f51e6f77b3029520/Shell.ahk
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb759795(v=vs.85).aspx
; ShellFileOperation("FO_MOVE", "::::", "::::","FOF_ALLOWUNDO|FOF_SIMPLEPROGRESS|FOF_NOCONFIRMMKDIR")
; MsgBox % ErrorLevel
ShellFileOperation( fileO=0x0, fSource="", fTarget="", flags=0x0, ghwnd=0x0 )
{
;dout_f(A_ThisFunc)
FO_MOVE := 0x1
FO_COPY := 0x2
FO_DELETE := 0x3
FO_RENAME := 0x4
FOF_MULTIDESTFILES := 0x1 ; Indicates that the to member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited.
FOF_SILENT := 0x4 ; Does not display a progress dialog box.
FOF_RENAMEONCOLLISION := 0x8 ; Gives the file being operated on a new name (such as "Copy #1 of...") in a move, copy, or rename operation if a file of the target name already exists.
FOF_NOCONFIRMATION := 0x10 ; Responds with "yes to all" for any dialog box that is displayed.
FOF_ALLOWUNDO := 0x40 ; Preserves undo information, if possible. With del, uses recycle bin.
FOF_FILESONLY := 0x80 ; Performs the operation only on files if a wildcard filename (*.*) is specified.
FOF_SIMPLEPROGRESS := 0x100 ; Displays a progress dialog box, but does not show the filenames.
FOF_NOCONFIRMMKDIR := 0x200 ; Does not confirm the creation of a new directory if the operation requires one to be created.
FOF_NOERRORUI := 0x400 ; don't put up error UI
FOF_NOCOPYSECURITYATTRIBS := 0x800 ; dont copy file security attributes
FOF_NORECURSION := 0x1000 ; Only operate in the specified directory. Don't operate recursively into subdirectories.
FOF_NO_CONNECTED_ELEMENTS := 0x2000 ; Do not move connected files as a group (e.g. html file together with images). Only move the specified files.
FOF_WANTNUKEWARNING := 0x4000 ; Send a warning if a file is being destroyed during a delete operation rather than recycled. This flag partially overrides FOF_NOCONFIRMATION.
; no more annoying numbers to deal with (but they should still work, if you really want them to)
fileO := %fileO% ? %fileO% : fileO
; the double ternary was too fun to pass up
_flags := 0
Loop Parse, flags, |
_flags |= %A_LoopField%
flags := _flags ? _flags : (%flags% ? %flags% : flags)
If ( SubStr(fSource,0) != "|" )
fSource := fSource . "|"
If ( SubStr(fTarget,0) != "|" )
fTarget := fTarget . "|"
char_size := A_IsUnicode ? 2 : 1
char_type := A_IsUnicode ? "UShort" : "Char"
fsPtr := &fSource
Loop % StrLen(fSource)
if NumGet(fSource, (A_Index-1)*char_size, char_type) = 124
NumPut(0, fSource, (A_Index-1)*char_size, char_type)
ftPtr := &fTarget
Loop % StrLen(fTarget)
if NumGet(fTarget, (A_Index-1)*char_size, char_type) = 124
NumPut(0, fTarget, (A_Index-1)*char_size, char_type)
/*
typedef struct _SHFILEOPSTRUCT {
HWND hwnd; A_PtrSize
UINT wFunc; 4
PCZZTSTR pFrom; <-- LPCWSTR, A_PtrSize
PCZZTSTR pTo; A_PtrSize
FILEOP_FLAGS fFlags; <-- WORD, 2
BOOL fAnyOperationsAborted;, 4
LPVOID hNameMappings; A_PtrSize
PCTSTR lpszProgressTitle; A_PtrSize
} SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;
Total:
A_PtrSize + 4 (+ 4 Padding) Padding + A_PtrSize + A_PtrSize + 2 + 2 Padding + 4 + A_PtrSize + A_PtrSize = 12 (+4) + 5 x A_PtrSize
*/
VarSetCapacity( SHFILEOPSTRUCT, 12 + 5 * A_PtrSize, 0) ; Encoding SHFILEOPSTRUCT
NumPut( ghwnd, &SHFILEOPSTRUCT, "PTR") ; hWnd of calling GUI
NumPut( fileO, SHFILEOPSTRUCT, A_PtrSize, "UINT") ; File operation
NumPut( fsPtr, SHFILEOPSTRUCT, 2 * A_PtrSize, "PTR") ; Source file / pattern
NumPut( ftPtr, SHFILEOPSTRUCT, 3 * A_PtrSize, "PTR" ) ; Target file / folder
NumPut( flags, SHFILEOPSTRUCT, 4 * A_PtrSize, "Short" ) ; options
DllCall( "Shell32\SHFileOperation" . (A_IsUnicode ? "W" : "A"), Ptr, &SHFILEOPSTRUCT )
SHFILEOPSTRUCT := ""
Return
}
================================================
FILE: register_schedule_task.bat
================================================
@echo off
SETLOCAL ENABLEEXTENSIONS
pushd %~dp0
set machotkey="machotkey.exe"
set taskname="machotkey"
:: escape double quotes and expand paths
for /f "delims=" %%v in ("%machotkey%") do set machotkey=%%~fv
for /f "delims=" %%v in ("%taskname%") do set taskname=%%~v
echo Register or unregister a schedule task to
echo automatic launch when your login.
echo.
echo Tip: You should run this as the administrator.
echo.
echo The mackhotkey file is %machotkey%
echo The taskname is %taskname%
echo.
if not exist "%machotkey%" (
echo File %machotkey% is not existed.
goto :err
)
if exist "%machotkey%\*" (
echo %machotkey% is not a file.
goto :err
)
goto :check
:check
schtasks.exe /Query /TN %taskname%>nul 2>nul
if ERRORLEVEL 1 goto :reg
goto :unreg
:reg
echo Register a schedule task: %taskname%
set /p tmpInput=Are you ready? (Y/N):^
if /i "%tmpInput%" neq "y" goto :cancel
schtasks.exe /Create /TN %taskname% /RU Users /SC ONLOGON /TR %machotkey%
if ERRORLEVEL 1 goto :err
echo OK
goto :end
:unreg
echo Unregister schedule task: %taskname%
set /p tmpInput=Are you ready? (Y/N):^
if /i "%tmpInput%" neq "y" goto :cancel
schtasks.exe /Delete /TN %taskname% /F
if ERRORLEVEL 1 goto :err
echo OK
goto :end
:cancel
echo Cancelled.
goto :over
:err
echo Failed.
goto :end
:end
echo Press any key to EXIT...
pause>nul
:over
popd