Skip to content

Instantly share code, notes, and snippets.

@PHPirates
Created October 11, 2018 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PHPirates/ec0804ca4534e05752e8fbaaccce3009 to your computer and use it in GitHub Desktop.
Save PHPirates/ec0804ca4534e05752e8fbaaccce3009 to your computer and use it in GitHub Desktop.
Autohotkey backups
#IfWinActive ahk_class AcrobatSDIWindow
!S::SendInput {Alt}vpc
#IfWinActive ahk_class AcrobatSDIWindow
!A::SendInput {Alt}vpt
^!S::
{
Run, "C:\Windows\Sysnative\SnippingTool.exe"\
WinWaitActive, Snipping Tool
Send ^n
}
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;|---------------|
;|--[ SOURCES ]--|
;|---------------|
;Base Spotify Script from: http://www.autohotkey.com/board/topic/36239-spotify-global-hotkeys/
;Base Starring Script from: http://superuser.com/questions/324416/any-spotify-tweaks-with-keyboard-shortcut-to-star-tracks
;|------------------|
;|--[ SETTING UP ]--|
;|------------------|
DetectHiddenWindows, On ;Detect Spotify even if it's minimized
#IfWinExist ahk_class SpotifyMainWindow ;Only do the following if Spotify is running
spotify = ahk_class SpotifyMainWindow ;Set variable for Spotify Window Name
;|---------------|
;|--[ HOTKEYS ]--|
;|---------------|
; "CTRL + ALT + PAGEUP" for previous
^!PGUP::
{
ControlSend, ahk_parent, ^{Left}, %spotify%
return
}
; "CTRL + ALT + PAGEDOWN" for next
^!PGDN::
{
ControlSend, ahk_parent, ^{Right}, %spotify%
return
}
; "CTRL + ALT + HOME" for pause
^!Home::
{
ControlSend, ahk_parent, {Space}, %spotify%
;ControlSend, ahk_parent, {Media_Play_Pause}, %spotify%
;Media_Play_Pause
return
}
; "CTRL + ALT + END" for track-name
^!End::
{
WinGetTitle, spotify_playing, %spotify% ;Get the title of Spotify which contains the track-name
StringTrimLeft, trimmed_playing, spotify_playing, 10 ;Get rid of extra text and place into 'trimmed_playing'
StringReplace, replaced_playing, trimmed_playing, –, -, All ;Replace en dash with normal dash and place into 'replaced_playing'
clipboard = %replaced_playing% ;Copy the fixed text to clipboard
return
}
; "CTRL + ALT + UP" for volume up
^!Up::
{
ControlSend, ahk_parent, ^{Up}, %spotify%
return
}
; "CTRL + ALT + DOWN" for volume down
^!Down::
{
ControlSend, ahk_parent, ^{Down}, %spotify%
return
}
; "CTRL + ALT + INSERT" for starring the current song
^!Insert::
{
;Store active window and mouse position.
MouseGetPos, , , winID
;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
clickX := 100
clickY := spotifyHeight-70
ControlClick, x%clickX% y%clickY% , %spotify%, , Right, , NA
;Get the contents of the context menu.
WinWait, ahk_class #32768
SendMessage, 0x1E1 ;MN_GETHMENU
allContextMenuInfo := ErrorLevel
;The "Star" command is the 2nd menu item.
;If the song is Unstarred the text is Star, and vice versa. But sometimes some wierd characters are included.
;The only reliable way I found is to check if the first letter is S.
menuText_StarUnstar := GetContextMenuItemText(allContextMenuInfo, 2)
StringGetPos, positionOfS, menuText_StarUnstar, S
;If S is the first letter, star the song.
notStarred := (%positionOfS% = 0)
If notStarred
{
;Arrow down to the Star menu item and press enter.
ControlSend, ahk_parent, {Down}{Down}{Enter}, %spotify%
}
Else
{
;Just close the context menu.
ControlSend, ahk_parent, {Escape}, %spotify%
}
;Restore original window and mouse position.
WinActivate ahk_id %winID%
return
}
;|-----------------|
;|--[ FUNCTIONS ]--|
;|-----------------|
;Context menu helper function.
GetContextMenuItemText(hMenu, nPos)
{
length := DllCall("GetMenuString"
, "UInt", hMenu
, "UInt", nPos
, "UInt", 0 ; NULL
, "Int", 0 ; Get length
, "UInt", 0x0400) ; MF_BYPOSITION
VarSetCapacity(lpString, length + 1)
length := DllCall("GetMenuString"
, "UInt", hMenu
, "UInt", nPos
, "Str", lpString
, "Int", length + 1
, "UInt", 0x0400)
return lpString
}
; "CTRL + RIGHT" for next
^Right::Media_Next
; "CTRL + LEFT" for previous
^Left::Media_Prev
; "CTRL + UP" for pause
^Up::Media_Play_Pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment