Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save digitalfun/61e4498e5e8d0a151c58fee9371ede40 to your computer and use it in GitHub Desktop.
Save digitalfun/61e4498e5e8d0a151c58fee9371ede40 to your computer and use it in GitHub Desktop.
DaByte's custom Mouse & Keyboard hotkeys for daily use
/*md
- File: .ahk_class; Type: Autohotkey script
- AHK Version: 1.6.0
- Author: Florian Schmid
- Copyright: florian SCHMID, [email protected]
- Notes:
*/
MYVERSION=1.8.0
Menu, Tray, Icon, icon.ICO, 1
Menu, Tray, Tip, Mouse and Keyboard macros by digitalfun v%MYVERSION%
/*md
VERSION HISTORY:
------------------------------
### 24.Okt.2016
+ 1.8.0
* added: Textmanipulation: Remove leading/trailing whitespaces
### 14.Jan.2016
+ 1.6.0
* added: convert to "Text-Table"
(source from <https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/pgTable/pgTable.ahk>)
### 12.Jan.2016
+ 1.5.0
* added: show/hide desktop icons
### 12.Feb.2015
+ 1.4.0
* added: Tray-menu entry for show-info
### 08.Aug.2014
+ 1.03
* added: CTRL + CapsLock | Textmanipulation
* added: helper functions `GetText()` and `PutText()`
### previous
+ 1.02
* added: Win + CTRL + Left/right/up
+ 1.00:
* initial release
*/
#Persistent
#SingleInstance
AutoTrim, On
SetTitleMatchMode, 2
; 1: A window's title must start with the specified WinTitle to be a match.
; 2: A window's title can contain WinTitle anywhere inside it to be a match.
; 3: A window's title must exactly match WinTitle to be a match.
;---------------------------------
; GLOBALS
;---------------------------------
g_TempText =
;----------------------------------
; GUI stuff
;----------------------------------
/*
pop-up-menu for Text-manipulation feature
*/
Menu menuTextManipulation, Add, &UPPERCASE, menuhandlerTextManipulation
Menu menuTextManipulation, Add, &lowercase, menuhandlerTextManipulation
Menu menuTextManipulation, Add, &Title Case, menuhandlerTextManipulation
Menu menuTextManipulation, Add, &Sentence case, menuhandlerTextManipulation
Menu menuTextManipulation, Add
Menu menuTextManipulation, Add, &Reverse, menuhandlerTextManipulation
Menu menuTextManipulation, Add, remove leading/trailing &whitespaces, menuhandlerTextManipulation
Menu menuTextManipulation, Add
Menu menuTextManipulation, Add, &Create "Text-Table", menuhandlerTextManipulation
;Tray-menu entry
Menu, tray, NoStandard ;remove standard items
Menu, tray, add ; Separator line.
Menu, tray, add, Manipulate Text, subManipulateText
Menu, tray, add, Show/Hide Desktop Icons, subShowHideDektopIcons
Menu, tray, add ; Separator line.
Menu, tray, add, Hotkeylist, subShowInfo
Menu, tray, add, ; Seperator line
Menu, tray, add, Exit, subExit
/*md
Hotkeys
=================================
*/
/*md
hotkey: `[PAUSE]`
---------------------
Mute/unmute the master volume.
*/
Pause::
Send {Volume_Mute}
Return
;; -----------------------------[WIN + CONTROL + LEFT-/RIGHT-Key]
; Simulate Win-7's Win-Left and Win-Right key functions.
/*
#^Left:: Win__HalfLeft()
#^Right:: Win__HalfRight()
;; -----------------------------[WIN + CONTROL + UP]
#^Up:: Win__FullSize()
;; -----------------------------[WIN + CONTROL + DOWN]
#^Down:: Win__Center()
*/
subExit:
ExitApp
Return
/*md
hotkey: `[CTRL]` + `[CAPSLOCK]`
----------------------------------
Show "Text manipulation"-menu:
*/
^CapsLock::
gosub subManipulateText
return ; ^CapsLock
/*md
hotkey: `[WIN]` + `h`
----------------------------------
Show/hide desktop icons.
*/
#h::
gosub subShowHideDektopIcons
Return
;----------------------------------
; Main
;----------------------------------
gosub subShowInfo
return ; Main
subShowInfo:
msg =
(LTrim
KEYBOARD:
[PAUSE] | Un-/Mute master volume
[WIN] + h | Show/Hide desktop icons
[CTRL] + [CAPSLOCK] | Manipulate text: lower, upper, reverse ...
)
MsgBox, %msg%
/* old hotkeys
[CTRL] + [WIN] + [Left/Right] | Resize window on left/right screen
[CTRL] + [WIN] + [Up] | Resize window to full-size
[CTRL] + [WIN] + [Down] | Center Window and resize to decent size
*/
return
/* sub subManipulateText
---------------------
Show "Text manipulation"-menu:
+ UPPERCASE
+ lowercase
+ Title Case
+ Sentence case
+ remove trailing/leading whitespaces
+ Reverse
**Note:**
If no text marked, take text from clipboard!
(if no text selected and no text in clipboard, nothing will happen)
*/
subManipulateText:
GetText(g_TempText)
if not (g_TempText = "") {
Menu menuTextManipulation, Show
} else {
g_TempText := Clipboard
Menu menuTextManipulation, Show
}
return
subShowHideDektopIcons:
ControlGet, HWND, Hwnd,, SysListView321, ahk_class Progman
If HWND =
ControlGet, HWND, Hwnd,, SysListView321, ahk_class WorkerW
If DllCall("IsWindowVisible", UInt, HWND)
WinHide, ahk_id %HWND%
Else
WinShow, ahk_id %HWND%
Return
;; -----------------------------------------------------------------------
; Get the position and size of the desktop, taking the taskbar area into account.
; This function probably doesn't work on secondary monitors.
Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
{
; Get dimensions of the system tray (taskbar)
WinGetPos, TrayX, TrayY, TrayW, TrayH, ahk_class Shell_TrayWnd
if (TrayW = A_ScreenWidth)
{
; Horizontal Taskbar
X := 0
Y := TrayY ? 0 : TrayH
W := A_ScreenWidth
H := A_ScreenHeight - TrayH
}
else
{
; Vertical Taskbar
X := TrayX ? 0 : TrayW
Y := 0
;W := A_ScreenWidth - TrayW
;H := A_ScreenHeight
W := A_ScreenWidth
H := A_ScreenHeight - TrayH
}
}
;; -----------------------------------------------------------------------
; Mimic Windows-7 Win-Left Key Combination
Win__HalfLeft()
{
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
}
;; -----------------------------------------------------------------------
; Mimic Windows-7 Win-Right Key Combination
Win__HalfRight()
{
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X + W/2, Y, W/2, H
}
Win__FullSize()
{
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
}
; The following function centers the specified window on the screen:
Win__Center()
{
Width := A_ScreenWidth - (A_ScreenWidth/6)
Height := A_ScreenHeight - (A_ScreenHeight/6)
WinMove, A,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2), Width, Height
}
; GUI EVENT HANDLER for menu
; Params: global variable `g_TempText` has to contain the text to modify.
; source: http://www.autohotkey.com/board/topic/25393-appskeys-a-suite-of-simple-utility-hotkeys/
menuhandlerTextManipulation:
; 1: UPPERCASE
If (A_ThisMenuItemPos = 1)
StringUpper, g_TempText, g_TempText
; 2: lowercase
Else If (A_ThisMenuItemPos = 2)
StringLower, g_TempText, g_TempText
; 3: Title Case
Else If (A_ThisMenuItemPos = 3)
StringLower, g_TempText, g_TempText, T
; 4: Sentence case
Else If (A_ThisMenuItemPos = 4)
{
StringLower, g_TempText, g_TempText
g_TempText := RegExReplace(g_TempText, "((?:^|[.!?]\s+)[a-z])", "$u1")
}
; 5: Seperator
; 6: Reverse
Else If (A_ThisMenuItemPos = 6)
{
Temp2 =
StringReplace, g_TempText, g_TempText, `r`n, % Chr(29), All
Loop Parse, g_TempText
Temp2 := A_LoopField . Temp2
StringReplace, g_TempText, Temp2, % Chr(29), `r`n, All
}
; 7: Remove leading/trailing whitespaces
Else If (A_ThisMenuItemPos = 7)
{
;g_TempText = %g_TempText%
g_TempText := Trim(g_TempText, " `t`r`n")
}
; 8: Seperator
; 9: create "Text-Table"
Else If (A_ThisMenuItemPos = 9)
{
g_TempText := Trim(g_TempText, " `t`r`n")
g_TempText := ConvertClipboardToTextTable(g_TempText)
}
PutText(g_TempText) ;paste result back
Return
; Copies the selected text to a variable while preserving the clipboard.
;source: http://www.autohotkey.com/board/topic/25393-appskeys-a-suite-of-simple-utility-hotkeys/
GetText(ByRef MyText = "")
{
SavedClip := ClipboardAll
Clipboard =
Send ^c
ClipWait 0.5
If ERRORLEVEL
{
Clipboard := SavedClip
MyText =
Return
}
MyText := Clipboard
Clipboard := SavedClip
Return
}
; Pastes text from a variable while preserving the clipboard.
;source: http://www.autohotkey.com/board/topic/25393-appskeys-a-suite-of-simple-utility-hotkeys/
PutText(MyText)
{
SavedClip := ClipboardAll
Clipboard = ; For better compatibility with Clipboard History
Clipboard := MyText
ClipWait
Send ^v
Sleep 100
Clipboard := SavedClip ;restore clipboard
Return
}
/* from: pgTable.ahk
Version: 1.0
Last time modified: 14.01.2016 16:43 by Florian SCHMID for "mouse n keyboard.ahk"
Description: a script to draw a pseudo-graphical borders to the copied table.
Script author: Drugoy a.k.a. Drugmix
Contacts: [email protected], [email protected]
https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/pgTable/pgTable.ahk
*/
ConvertClipboardToTextTable(in_text)
{
;{ Settings
;{ Available border styles
borderThin := "-¦+-+++¦+-+"
borderDouble := "-¦+-+¦+¦+-+"
border21 := "-¦+-+¦+¦+-+"
border12 := "-¦+-+¦+¦+-+"
;}
border := borderThin ; Specify the choice of border style here
useTopBorder := 1 ; Choose whether to add a top border to the table
useRowSeparatingBorders := 1 ; Choose whether to use horizontal borders betweel rows
useBottomBorder := 1 ; Choose whether to add a bottom border to the table
horizontalCellPadding := 0 ; Choose the number of spaces to be added as horizontal paddings (to the left and to the right from each cell's value)
textAlign := 0 ; Choose how to align text in cells: left/center/right = -1/0/1
;}
;{ Convert the input table into an array
inputArray := []
Loop, Parse, in_text, `n ; Per line parsing of input.
{
rows := A_Index ; At the end of loop, variable "rows" will contain the number of rows.
Loop, Parse, A_LoopField, `t
inputArray[A_Index, rows] := RTrim(A_LoopField, "`r`n") ; Have to cut away `r`n from the right edge of cells, since every row's last cell has them.
}
;}
;{ Transform a table into a text table with pseudo-graphics
columns := inputArray.MaxIndex()
topBorder := bottomBorder := output := rowSeparator := ""
Loop, % rows
{
thisRow := A_Index
Loop, % columns
{
thisColMaxWidth := getColMaxWidth(A_Index)
thisCellWidth := StrLen(inputArray[A_Index, thisRow])
; While parsing first row, the script (based on the specified settings)
; decides whether to build table's top border, bottom border
; and row separating horizontal borders.
If (thisRow == 1)
{
;{ Build the table's top border.
If (useTopBorder)
{
If (A_Index == 1) ; Parsing leftmost cell.
topBorder := SubStr(border, 3, 1) ; +
Loop, % thisColMaxWidth + 2 * horizontalCellPadding
topBorder .= SubStr(border, 1, 1) ; -
If (A_Index != columns)
topBorder .= SubStr(border, 4, 1) ; -
Else ; Parsing rightmost cell.
topBorder .= SubStr(border, 5, 1) "`n" ; +
}
;}
;{ Build the table's rows horizontal separator.
If (useRowSeparatingBorders)
{
If (A_Index == 1)
rowSeparator .= SubStr(border, 6, 1) ; +
Loop, % thisColMaxWidth + 2 * horizontalCellPadding
rowSeparator .= SubStr(border, 1, 1) ; -
If (A_Index != columns)
rowSeparator .= SubStr(border, 7, 1) ; +
Else ; Parsing rightmost cell.
rowSeparator .= SubStr(border, 8, 1) "`n" ; ¦
}
;}
;{ Build the table's bottommost line.
If (useBottomBorder)
{
If (A_Index == 1) ; Parsing leftmost cell.
bottomBorder := "`n" SubStr(border, 9, 1) ; +
Loop, % thisColMaxWidth + 2 * horizontalCellPadding
bottomBorder .= SubStr(border, 1, 1) ; -
If (A_Index != columns)
bottomBorder .= SubStr(border, 10, 1) ; -
Else ; Parsing rightmost cell.
bottomBorder .= SubStr(border, 11, 1) ; +
}
;}
}
;{ Defining the number of spaces at left and at right from the cell's text value.
If (A_Index = 1) ; Parsing leftmost cell.
output .= SubStr(border, 2, 1) ; ¦
cellLeftSpacing := cellRightSpacing := horizontalCellPadding ; Counting the number of spaces to add at left from the value.
If (textAlign = "1") ; Right text alignment
cellLeftSpacing += thisColMaxWidth - thisCellWidth
Else If (textAlign = "-1") ; Left text alignment
cellRightSpacing += thisColMaxWidth - thisCellWidth
Else If (thisColMaxWidth - thisCellWidth) ;
{
cellLeftSpacing += Ceil((thisColMaxWidth - thisCellWidth) / 2)
cellRightSpacing += Floor((thisColMaxWidth - thisCellWidth) / 2)
}
Loop, % cellLeftSpacing
(A_Index = 1 ? cellLeftSpacing := " " : cellLeftSpacing .= " ")
Loop, % cellRightSpacing
(A_Index = 1 ? cellRightSpacing := " " : cellRightSpacing .= " ")
;}
output .= (cellLeftSpacing ? cellLeftSpacing : "") inputArray[A_Index, thisRow] (cellRightSpacing ? cellRightSpacing : "") SubStr(border, 2, 1) ; ¦
}
If (useRowSeparatingBorders) && (A_Index != rows) ; Concatenate a row separating border to the currently formed row.
output .= "`n" rowSeparator
}
output := topBorder output bottomBorder
;}
;{ Store the pseudo-graphics table into clipboard
Clipboard := output
ClipWait
;}
Return output
}
getColMaxWidth(colN)
{
Global
Local this, local that
Loop, % rows
{
that := StrLen(inputArray[colN, A_Index])
this < that ? this := that
}
Return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment