Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AppsKeys - a "suite" of simple utility hotkeys


  • Please log in to reply
16 replies to this topic
ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
This is basically just a trimmed down version of the AutoHotkey script I keep running all the time for my own use. Hopefully someone else will find some of them useful. They include hotkeys for hiding windows, making them always on top, formatting text, unformatting text, using the highlighted text as a URL or Google search, among other things. See the commend at the top for a full list.

#SingleInstance Force
#NoEnv
SendMode Input
SetTitleMatchMode 2

;******************************************************************************
; This is a random selection of utilities. All are activated by holding 
; "Application Key" (left of right Ctrl) and pressing some other key. 
; Some of them have a second function activated by holding Shift at the 
; same time. Hopefully you will find some of the useful. Feel free to 
; modify, reuse or share any of this.
;
; AppsKey plus - Result
;
;        Enter - Inserts a linebreak.
;                For use when pressing enter would submit a form.
;          Tab - Inserts a tab.
;                For use when pressing tab would change the focus.
;   Arrow Keys - Move the mouse with the arrow keys.
;                For use when you need pixel-precise control.
;       Insert - Searches for the slected text with Google. Or if the text
;                is a URL, goes directly there. See BROWSER CONFIG below.
;    Caps Lock - Opens a context menu with commands to change the case of
;                the selected text, reverse it or "fix" Unix style newlines.
;           F1 - Shows the AutoHotkey help file.
;           F4 - Terminates active application after confirmation.
;                This is like using the Ctrl+Alt+Delete menu.
;     SHIFT F4 - As above, but skips confirmation window.
;  Windows Key - Disables the Windows keys. For use with fullscreen games.
;                Press both windows keys at once to re-enable them.
;            A - Makes the active window "Always On Top".
;                This will be indicated on it's title bar with a †.
;      SHIFT A - Makes the active window NOT "Always On Top".
;            C - Eject the CD tray.   |Handy if the computer is on the floor
;      SHIFT C - Retract the CD tray. |or otherwise awkward to reach.
;            B   Turns the monitor off, similar to power saving mode.
;                Moving the mouse or typing will turn it back on.
;            E - Opens this script for editing.
;            H - Hides the active window.
;      SHIFT H - Unhide all windows that were hidden this way.
;            L - Launch (run) a script selected in explorer.
;                For use when .ahk is not associated with AutoHotkey.
;            R - Reloads this script.
;                If the active window is this script, it will be saved first.
;            T - Makes the active window 50% transpartent.
;      SHIFT T - Makes the active window opaque again.
;            V - Pastes clipboard contents as plain text (if possible).
;                If you "copy" files, this will paste their paths.
;            W - Wraps text to a specific width. (Default 70).
;      SHIFT W - Undoes the above.
;            X - Shows a custom shutdown menu. Press a letter to select from:
;                Shutdown, Restart, Log Off, Hibernate or Powersave (suspend).
;            / - Do a RegEx replace on selected text.
;            [ - Creates matching BBCode tags. (Applied to selected text)
;            , - Creates matching HTML tags. (Ditto)
;            ; - Comments/Uncomments a block of AutoHotkey code.

; BROWSER CONFIG
; This should be the full path to your preferred web browser.
; Example: C:\Program Files\Mozilla Firefox\Firefox.exe

BrowserPath = 

;******************************************************************************

GroupAdd All

Menu Case, Add, &UPPERCASE, CCase
Menu Case, Add, &lowercase, CCase
Menu Case, Add, &Title Case, CCase
Menu Case, Add, &Sentence case, CCase
Menu Case, Add
Menu Case, Add, &Fix Linebreaks, CCase
Menu Case, Add, &Reverse, CCase

;******************************************************************************

AppsKey::
;Keep AppsKey working (mostly) normally.
Send {AppsKey}
Return

AppsKey & enter::
PutText("`r`n")
Return

AppsKey & tab::
PutText("`t")
Return

AppsKey & Left::MouseMove, -1, 0, 0, R
AppsKey & Right::MouseMove, 1, 0, 0, R
AppsKey & Up::MouseMove, 0, -1, 0, R
AppsKey & Down::MouseMove, 0, 1, 0, R

AppsKey & Insert::
TempText := GetText()
TempText := RegExReplace(TempText, "^\s+|\s+$") ;trim whitespace
If RegExMatch(TempText, "\w\.[a-zA-Z]+(/|$)") ;contains .com etc
{
   If SubStr(TempText, 1, 4) != "http"
      TempText := "http://" . TempText
}
Else
{
   If InStr(TempText, " ")
   {
      StringReplace TempText, TempText, %A_Space%, +
      TempText := "%22" . TempText . "%22"
   }
   TempText := "http://www.google.com/search?&q=" . TempText
}
Run %BrowserPath% %TempText%
Return

AppsKey & CapsLock::
GetText(TempText)
If NOT ERRORLEVEL
   Menu Case, Show
Return

AppsKey & F1::
IfWinExist AutoHotkey Help
   WinActivate AutoHotkey Help
Else
{
   SplitPath A_AhkPath, , TempText
   Run %TempText%\AutoHotkey.chm
}
Return

AppsKey & F4::
MyWin := WinExist("A")
WinGetTitle TempText, ahk_id %MyWin%
If NOT TempText ;Prevents terminated the taskbar, or the like.
   Return
If NOT GetKeyState("shift")
{
   WinGetTitle TempText, ahk_id %MyWin%
   MsgBox 49, Terminate!, Terminate "%TempText%"?`nUnsaved data will be lost.
   IfMsgBox Cancel
      Return
}
WinGet MyPID, PID, ahk_id %MyWin%
Process, Close, %MyPID%
Return

AppsKey & RWin::
AppsKey & LWin::
Hotkey RWin, DoNothing, On
Hotkey LWin, DoNothing, On
Return
;;;;;;;;;;;
Lwin & RWin::
Rwin & LWin::
Hotkey RWin, DoNothing, Off
Hotkey LWin, DoNothing, Off
Return
DoNothing:
Return

AppsKey & a::
If NOT IsWindow(WinExist("A"))
   Return
WinGetTitle, TempText, A
If GetKeyState("shift")
{
   WinSet AlwaysOnTop, Off, A
   If (SubStr(TempText, 1, 2) = "† ")
      TempText := SubStr(TempText, 3)
}
else
{
   WinSet AlwaysOnTop, On, A
   If (SubStr(TempText, 1, 2) != "† ")
      TempText := "† " . TempText ;chr(134)
}
WinSetTitle, A, , %TempText%
Return

AppsKey & b::
SendMessage, 0x112, 0xF170, 1,, Program Manager
Sleep 1000
SendMessage, 0x112, 0xF170, 1,, Program Manager
Return


AppsKey & c::
Drive Eject,, % GetKeyState("shift")
Return

AppsKey & e::Edit

AppsKey & h::
If GetKeyState("shift")
{
   Loop Parse, HiddenWins, |
      WinShow ahk_id %A_LoopField%
   HiddenWins =
}
else
{
   MyWin := WinExist("A")
   if IsWindow(MyWin) 
   {
      HiddenWins .= (HiddenWins ? "|" : "") . MyWin
      WinHide ahk_id %MyWin%
      GroupActivate All
   }
}
Return

AppsKey & l::
TempText := GetText()
If FileExist(TempText)
   Run %A_AhkPath% "%TempText%"
Else
   MsgBox Before using this command, select the .ahk file you wish to run in windows explorer.
Return

AppsKey & r::
KeyWait AppsKey
IfWinActive %A_ScriptName%
   Send ^s ;Save
Reload
Return

AppsKey & t::
If NOT IsWindow(WinExist("A"))
   Return
If GetKeyState("shift")
   Winset, Transparent, OFF, A
else
   Winset, Transparent, 128, A
Return

AppsKey & v::
TempText := ClipBoard
If (TempText != "")
   PutText(ClipBoard)
Return

AppsKey & w::
GetText(TempText)
If NOT WrapWidth
   WrapWidth := "70"
If GetKeyState("shift")
   StringReplace TempText, TempText, %A_Space%`r`n, %A_Space%, All
else
{
   Temp2 := SafeInput("Enter Width", "Width:", WrapWidth)
   If ErrorLevel
      Return
   WrapWidth := Temp2
   Temp2 := "(?=.{" . WrapWidth + 1 . ",})(.{1," . WrapWidth - 1 . "}[^ ]) +"
   TempText := RegExReplace(TempText, Temp2, "$1 `r`n")
}
PutText(TempText)
Return

AppsKey & x::
SplashImage, , MC01, (S) Shutdown`n(R) Restart`n(L) Log Off`n(H) Hibernate`n(P) Power Saving Mode`n`nPress ESC to cancel., Press A Key:, Shutdown?, Courier New
Input TempText, L1
SplashImage, Off
If (TempText = "S")
   ShutDown 8
Else If (TempText = "R")
   ShutDown 2
Else If (TempText = "L")
   ShutDown 0
Else If (TempText = "H")
   DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
Else If (TempText = "P")
   DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
Return

AppsKey & /::
; RegEx Replace
TempText := SafeInput("Enter Pattern", "RegEx Pattern:", REPatern)
If ErrorLevel
   Return
Temp2 := SafeInput("Enter Replacement", "Replacement:", REReplacement)
If ErrorLevel
   Return
REPatern := TempText
REReplacement := Temp2
GetText(TempText)
TempText := RegExReplace(TempText, REPatern, REReplacement)
PutText(TempText)
Return

AppsKey & ,::
TempText := SafeInput("Enter Tag", "Example: a href=""http://www.autohotkey.com/""", HTFormat)
If ErrorLevel
   Return
If SubStr(TempText, 1, 4) = "http"
   TempText = a href="%TempText%"
HTFormat := TempText
GetText(Temp2)
Temp2 := "<" . TempText . ">" . Temp2
TempText := RegExReplace(TempText, " .*")
Temp2 := Temp2 . "</" . TempText . ">"
PutText(Temp2)
Return

AppsKey & [::
TempText := SafeInput("Enter Tag", "Example: color=red", BBFormat)
If ErrorLevel
   Return
If SubStr(TempText, 1, 4) = "http"
   TempText = url=%TempText%
BBFormat := TempText
GetText(Temp2)
If SubStr(TempText, 1, 4) = "list" AND NOT InStr(Temp2, "[*]")
   Temp2 := RegExReplace(Temp2, "m`a)^(\*\s*)?", "[*]")
Temp2 := "[" . TempText . "]" . Temp2
TempText := RegExReplace(TempText, "=.*")
Temp2 := Temp2 . "[/" . TempText . "]"
PutText(Temp2)
Return

AppsKey & `;::
;Comment or uncomment AutoHotkey code
GetText(TempText)
If (SubStr(TempText, 1, 1) = ";")
   TempText := RegExReplace(TempText, "`am)^;")
Else
   TempText := RegExReplace(TempText, "`am)^", ";")
PutText(TempText)
Return

;******************************************************************************
CCase:
If (A_ThisMenuItemPos = 1)
   StringUpper, TempText, TempText
Else If (A_ThisMenuItemPos = 2)
   StringLower, TempText, TempText
Else If (A_ThisMenuItemPos = 3)
   StringLower, TempText, TempText, T
Else If (A_ThisMenuItemPos = 4)
{
   StringLower, TempText, TempText
   TempText := RegExReplace(TempText, "((?:^|[.!?]\s+)[a-z])", "$u1")
} ;Seperator, no 5
Else If (A_ThisMenuItemPos = 6)
{
   TempText := RegExReplace(TempText, "\R", "`r`n")
}
Else If (A_ThisMenuItemPos = 7)
{
   Temp2 =
   StringReplace, TempText, TempText, `r`n, % Chr(29), All
   Loop Parse, TempText
      Temp2 := A_LoopField . Temp2
   StringReplace, TempText, Temp2, % Chr(29), `r`n, All
}
PutText(TempText)
Return

;******************************************************************************

; Handy function.
; Copies the selected text to a variable while preserving the clipboard.
GetText(ByRef MyText = "")
{
   SavedClip := ClipboardAll
   Clipboard =
   Send ^c
   ClipWait 0.5
   If ERRORLEVEL
   {
      Clipboard := SavedClip
      MyText =
      Return
   }
   MyText := Clipboard
   Clipboard := SavedClip
   Return MyText
}

; Pastes text from a variable while preserving the clipboard.
PutText(MyText)
{
   SavedClip := ClipboardAll 
   Clipboard =              ; For better compatability
   Sleep 20                 ; with Clipboard History
   Clipboard := MyText
   Send ^v
   Sleep 100
   Clipboard := SavedClip
   Return
}

;This makes sure sure the same window stays active after showing the InputBox.
;Otherwise you might get the text pasted into another window unexpectedly.
SafeInput(Title, Prompt, Default = "")
{
   ActiveWin := WinExist("A")
   InputBox OutPut, %Title%, %Prompt%,,, 120,,,,, %Default%
   WinActivate ahk_id %ActiveWin%
   Return OutPut
}

;This checks if a window is, in fact a window.
;As opposed to the desktop or a menu, etc.
IsWindow(hwnd) 
{
   WinGet, s, Style, ahk_id %hwnd% 
   return s & 0xC00000 ? (s & 0x80000000 ? 0 : 1) : 0
   ;WS_CAPTION AND !WS_POPUP(for tooltips etc) 
}


Gakusei
  • Members
  • 16 posts
  • Last active: Dec 13 2011 01:03 PM
  • Joined: 09 Jan 2008
Great stuff.

Thanks

Pierre
  • Members
  • 19 posts
  • Last active: Jun 12 2008 09:26 AM
  • Joined: 17 Nov 2007
I get some "This line does not contain a recognized action." e.g. on line 143 RegRead, BrowserPath, HKCR, HTTP\Shell\Open\Command or line 205 If SubStr(TempText, 1, 4) != "http"

This happened to me with other scripts too. My AHK is ver 1.0.47.5

Any idea?
P.

Pierre
  • Members
  • 19 posts
  • Last active: Jun 12 2008 09:26 AM
  • Joined: 17 Nov 2007
Nevermind, that was a spaces/tabs issue in my editor (the scite version configured for AHK)
P.

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
I accidentally left some debug code in there, which tied up the F1 key. Please download again (or remove it yourself, it's the line "F1::MSGBOX %BrowserPath%")

Sorry 'bout that.

keybored
  • Members
  • 351 posts
  • Last active: Apr 26 2013 09:08 AM
  • Joined: 18 Jun 2006
ManaUser,
I particularly like these;
GetText() = I was going to write a function for this myself.
Searches for with Google Or Url (clever dual useage!)
; -Comments/Uncomments AutoHotkey code. This makes sense! With /*... */ it's harder to see what's commented!

Hope you update this later on. Thanks Keybored

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Thanks.

; -Comments/Uncomments AutoHotkey code. This makes sense! With /*... */ it's harder to see what's commented!

Yes, I never got in the habit using /* and */. I guess it's good for long comments, e.g. at the top of a a script, but I definitely wouldn't use them for "commenting out" code, too confusing.

Hope you update this later on. Thanks Keybored

I'll do that, if i think of anything to add.

By the way, there are a couple undocumented features in the HTML and BBCode tag makers. (Though I guess now that I've posted this they're no longer undocumented.) If you enter a URL (with http) instead of a tag it will add a href= or url= as appropriate. Handy if you copy and paste from the address bar. And in the BBCode creator only, it will add [*] to each line when applying a [list] tag, if needed.

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Added a new one. AppsKey & X, which shows a menu with options to Shutdown, Restart, Log Off, Hibernate or suspend (labeled Power Saving Mode, to avoid a duplicate letter). Press the first letter to choose one, press ESC (or anything but S,R,L,H or P, actually) to cancel. Hibernate will do the same as suspend unless hibernating has been enabled on your system.

RiseUp
  • Members
  • 38 posts
  • Last active: Jan 04 2016 01:42 PM
  • Joined: 06 Dec 2007
This is a great script, ManaUser. I'm sure I'll be having this as one of my always-running scripts. Thanks for posting it!

:D

System Monitor
  • Members
  • 508 posts
  • Last active: Mar 26 2012 05:13 AM
  • Joined: 09 Mar 2007
Awesome! Thanks for posting

epconfig
  • Members
  • 30 posts
  • Last active: Feb 12 2015 12:17 AM
  • Joined: 10 Oct 2007
Great, you gave me new ideas for my own allways running 120 hotkey-macros script.

Why are you using “KeyWait” on your “Reload” macro and not anywhere else in your script. Is it because you are sending ^S in this macro?

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Two new commands.

AppsKey & W
Wraps text to a specific number of characters.

AppsKey & /
Does a Regular Expression replace anywhere.

Jimmy2Times
  • Members
  • 65 posts
  • Last active: Jul 15 2014 07:56 PM
  • Joined: 07 Apr 2004
Very useful, thank you

codybear
  • Members
  • 600 posts
  • Last active: Feb 09 2015 12:41 PM
  • Joined: 15 Sep 2009
Nice, you got a couple good gems inside there that I never really thought of before.
Here's an older list of what's in mine, only minor things have changed and have been added to the list.

<!-- m -->http://www.autohotke... ... 231#344231<!-- m -->

If you'd like some coding out of it, let me know (through PM please).

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
For some reason, I missed this post when it was first published. I found it via the « Your favorite AHK script(s) » post. There are few gems in here that are pretty cool. Thanks for sharing and keep up the good work! :)

Edit: Fixed link.