AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AppsKeys - a "suite" of simple utility hotkeys

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
ManaUser



Joined: 24 May 2007
Posts: 901

PostPosted: Mon Jan 21, 2008 8:54 pm    Post subject: AppsKeys - a "suite" of simple utility hotkeys Reply with quote

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.

Code:
#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".
;            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.
;            X - Shows a custom shutdown menu. Press a letter to select from:
;                Shutdown, Restart, Log Off, Hibernate or Powersave (suspend).
;            [ - Creates matching BBCode tags. (Applied to selected text)
;            , - Creates matching HTML tags. (Applied to selected text)
;            ; - 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")
If NOT IsWindow(MyWin)
   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 & 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, , T1
If ErrorLevel
   Return
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 & 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 & ,::
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"
   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.1
   If ERRORLEVEL
   {
      Clipboard := SavedClip
      MyText =
      ERRORLEVEL := 1
      Return
   }
   MyText := Clipboard
   Clipboard := SavedClip
   Return MyText
}

; Pastes text from a variable while preserving the clipboard.
PutText(MyText)
{
   SavedClip := ClipboardAll
   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)
}


Last edited by ManaUser on Sat Jan 26, 2008 7:31 pm; edited 2 times in total
Back to top
View user's profile Send private message
Gakusei



Joined: 09 Jan 2008
Posts: 15

PostPosted: Tue Jan 22, 2008 2:48 pm    Post subject: Reply with quote

Great stuff.

Thanks
Back to top
View user's profile Send private message
Pierre



Joined: 17 Nov 2007
Posts: 19

PostPosted: Tue Jan 22, 2008 4:11 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Pierre



Joined: 17 Nov 2007
Posts: 19

PostPosted: Tue Jan 22, 2008 4:21 pm    Post subject: Reply with quote

Nevermind, that was a spaces/tabs issue in my editor (the scite version configured for AHK)
P.
Back to top
View user's profile Send private message
ManaUser



Joined: 24 May 2007
Posts: 901

PostPosted: Tue Jan 22, 2008 6:45 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
keybored



Joined: 18 Jun 2006
Posts: 90
Location: Phoenix, AZ

PostPosted: Thu Jan 24, 2008 3:51 pm    Post subject: Thanks for sharing this! Reply with quote

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
Back to top
View user's profile Send private message
ManaUser



Joined: 24 May 2007
Posts: 901

PostPosted: Fri Jan 25, 2008 4:36 am    Post subject: Re: Thanks for sharing this! Reply with quote

Thanks.
keybored wrote:
; -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.

keybored wrote:
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.
Back to top
View user's profile Send private message
ManaUser



Joined: 24 May 2007
Posts: 901

PostPosted: Sat Jan 26, 2008 7:47 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
pockinator



Joined: 06 Dec 2007
Posts: 33

PostPosted: Mon Mar 31, 2008 1:10 am    Post subject: Reply with quote

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!

Very Happy


Last edited by pockinator on Mon Mar 31, 2008 2:57 am; edited 1 time in total
Back to top
View user's profile Send private message
System Monitor



Joined: 09 Mar 2007
Posts: 392
Location: Unknown

PostPosted: Mon Mar 31, 2008 1:38 am    Post subject: Reply with quote

Awesome! Thanks for posting
_________________
Back to top
View user's profile Send private message Visit poster's website
epconfig



Joined: 10 Oct 2007
Posts: 19
Location: Montreal, Canada

PostPosted: Sun Apr 06, 2008 6:45 pm    Post subject: Reply with quote

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?
_________________
epconfig
Enterpad Keyboard for AutoHotkey
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group