AutoHotkey Community

It is currently May 27th, 2012, 10:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 21st, 2008, 8:54 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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".
;            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)
}


Last edited by ManaUser on November 14th, 2008, 7:42 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2008, 2:48 pm 
Offline

Joined: January 9th, 2008, 9:07 pm
Posts: 16
Great stuff.

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2008, 4:11 pm 
Offline

Joined: November 17th, 2007, 6:10 pm
Posts: 19
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2008, 4:21 pm 
Offline

Joined: November 17th, 2007, 6:10 pm
Posts: 19
Nevermind, that was a spaces/tabs issue in my editor (the scite version configured for AHK)
P.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2008, 6:45 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks for sharing this!
PostPosted: January 24th, 2008, 3:51 pm 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 25th, 2008, 4:36 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2008, 7:47 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 31st, 2008, 1:10 am 
Offline

Joined: December 6th, 2007, 4:21 pm
Posts: 32
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


Last edited by pockinator on March 31st, 2008, 2:57 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 31st, 2008, 1:38 am 
Offline

Joined: March 9th, 2007, 2:47 am
Posts: 509
Location: Unknown
Awesome! Thanks for posting


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2008, 6:45 pm 
Offline

Joined: October 10th, 2007, 7:43 pm
Posts: 29
Location: Montreal, Canada
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2008, 7:46 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Two new commands.

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

AppsKey & /
Does a Regular Expression replace anywhere.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2010, 11:13 pm 
Offline

Joined: April 7th, 2004, 2:43 pm
Posts: 62
Very useful, thank you


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2010, 3:11 am 
Offline

Joined: September 15th, 2009, 1:14 am
Posts: 562
Location: Tempe, Arizona
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.

http://www.autohotkey.com/forum/viewtop ... 231#344231

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 6th, 2011, 11:04 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Last edited by jballi on June 6th, 2011, 2:31 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group