Skip to content

Instantly share code, notes, and snippets.

@taimursaeed
Last active November 5, 2019 11:31
Show Gist options
  • Save taimursaeed/d084da0caf4be877a03c1f5680dd393c to your computer and use it in GitHub Desktop.
Save taimursaeed/d084da0caf4be877a03c1f5680dd393c to your computer and use it in GitHub Desktop.
My Autohotkey Shortcuts for PC
^!d::RUN,"C:\Users\PC\Downloads"
^!n::RUN,"Notepad"
^!1::RUN,"Chrome"
^!2::RUN,"C:\Program Files\Mozilla Firefox\firefox.exe"
^!3::RUN,"C:\Program Files\Internet Explorer\iexplore.exe"
^!4::Run microsoft-edge:https://autohotkey.com
^!0::RUN,"C:\Program Files\Sublime Text 3\sublime_text.exe"
^SPACE:: Winset, Alwaysontop, , A
#$WheelUp::
Send {Volume_Up}
Return
; Shift + Wheel for horizontal scrolling
+WheelDown::WheelRight
+WheelUp::WheelLeft
#Singleinstance Force
;Horizontal scrolling in Excel only
#IfWinActive ahk_class XLMAIN
+WheelUp::
SetScrollLockState, On
SendInput {Left}
SetScrollLockState, Off
Return
+WheelDown::
SetScrollLockState, On
SendInput {Right}
SetScrollLockState, Off
Return
; Horizontal scrolling in everything except Excel.
#IfWinNotActive ahk_class XLMAIN
+WheelDown::WheelRight
+WheelUp::WheelLeft
;;;;Swtiching Desktops in windows 10
AppsKey & RCtrl:: ; switch to next desktop with Windows key + Left Alt key
KeyWait LAlt
SendInput #^{Right}
Return
AppsKey & RAlt:: ; switch to previous desktop with Windows key + Left CTRL key
KeyWait LCtrl
SendInput #^{Left}
Return
; Windows and C closes active window
^q::
WinGetTitle, Title, A
PostMessage, 0x112, 0xF060,,, %Title%
return
#$WheelDown::
Send {Volume_Down}
Return
#If (WinActive("ahk_class Chrome_WidgetWin_1") or Winactive("ahk_class IEFrame")) ; Chrome or IE
;+WheelUp:: Send,{CtrlDown}{ShiftDown}{Tab}{ShiftUp}{CtrlUp}
;+WheelDown:: Send, {CtrlDown}{Tab}{CtrlUp} ; "+" means Shift
; This is part of my AutoHotKey [1] script. When you are in Windows Explorer it
; allows you to press Ctrl+Alt+N and type a filename, and that file is created
; in the current directory and opened in the appropriate editor (usually
; [gVim](http://www.vim.org/) in my case, but it will use whatever program is
; associated with the file in Windows Explorer).
; This is much easier than the alternative that I have been using until now:
; Right click > New > Text file, delete default filename and extension (which
; isn't highlighted in Windows 7), type the filename, press enter twice.
; (Particularly for creating dot files like ".htaccess".)
; Credit goes to aubricus [2] who wrote most of this - I just added the
; 'IfWinActive' check and 'Run %UserInput%' at the end.
; [1]: http://www.autohotkey.com/
; [2]: https://gist.github.com/1148174
; Only run when Windows Explorer or Desktop is active
; Ctrl+Alt+N
#IfWinActive ahk_class CabinetWClass
^!k::
#IfWinActive ahk_class ExploreWClass
^!k::
#IfWinActive ahk_class Progman
^!k::
#IfWinActive ahk_class WorkerW
^!k::
; Get full path from open Explorer window
WinGetText, FullPath, A
; Clean up result
StringReplace, FullPath, FullPath, `r, , all
FullPath := RegExReplace(FullPath, "^.*`nAddress: ([^`n]+)`n.*$", "$1")
; Change working directory
SetWorkingDir, %FullPath%
; An error occurred with the SetWorkingDir directive
If ErrorLevel
Return
; Display input box for filename
InputBox, UserInput, New File (example: foo.txt), , , 400, 100
; User pressed cancel
If ErrorLevel
Return
; Create file
FileAppend, , %UserInput%
; Open the file in the appropriate editor
Run %UserInput%
Return
#IfWinActive
; This script modified from the original: http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm
; by The How-To Geek
; http://www.howtogeek.com
Alt & LButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return
;;;;;;;;;;;;;;;; brightness shortcuts for surface type cover ;;;;;;;;;;;;;;;;;;
toggle := false
SetWorkingDir %A_ScriptDir%
SendMode, Input
;;SC108:: ; SAMSUNG brightness up FN key
;;^+#!Up::
!WheelUp::
MoveBrightness(3)
return
;;SC109:: ; SAMSUNG brightness down FN key
;;^+#!Down::
!WheelDown::
MoveBrightness(-3)
return
#Escape::SendMessage 0x112, 0xF170, 2, , Program Manager
;############################################################################
; Functions
;############################################################################
MoveBrightness(IndexMove)
{
VarSetCapacity(SupportedBrightness, 256, 0)
VarSetCapacity(SupportedBrightnessSize, 4, 0)
VarSetCapacity(BrightnessSize, 4, 0)
VarSetCapacity(Brightness, 3, 0)
hLCD := DllCall("CreateFile"
, Str, "\\.\LCD"
, UInt, 0x80000000 | 0x40000000 ;Read | Write
, UInt, 0x1 | 0x2 ; File Read | File Write
, UInt, 0
, UInt, 0x3 ; open any existing file
, UInt, 0
, UInt, 0)
if hLCD != -1
{
DevVideo := 0x00000023, BuffMethod := 0, Fileacces := 0
NumPut(0x03, Brightness, 0, "UChar") ; 0x01 = Set AC, 0x02 = Set DC, 0x03 = Set both
NumPut(0x00, Brightness, 1, "UChar") ; The AC brightness level
NumPut(0x00, Brightness, 2, "UChar") ; The DC brightness level
DllCall("DeviceIoControl"
, UInt, hLCD
, UInt, (DevVideo<<16 | 0x126<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS
, UInt, 0
, UInt, 0
, UInt, &Brightness
, UInt, 3
, UInt, &BrightnessSize
, UInt, 0)
DllCall("DeviceIoControl"
, UInt, hLCD
, UInt, (DevVideo<<16 | 0x125<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS
, UInt, 0
, UInt, 0
, UInt, &SupportedBrightness
, UInt, 256
, UInt, &SupportedBrightnessSize
, UInt, 0)
ACBrightness := NumGet(Brightness, 1, "UChar")
ACIndex := 0
DCBrightness := NumGet(Brightness, 2, "UChar")
DCIndex := 0
BufferSize := NumGet(SupportedBrightnessSize, 0, "UInt")
MaxIndex := BufferSize-1
Loop, %BufferSize%
{
ThisIndex := A_Index-1
ThisBrightness := NumGet(SupportedBrightness, ThisIndex, "UChar")
if ACBrightness = %ThisBrightness%
ACIndex := ThisIndex
if DCBrightness = %ThisBrightness%
DCIndex := ThisIndex
}
if DCIndex >= %ACIndex%
BrightnessIndex := DCIndex
else
BrightnessIndex := ACIndex
BrightnessIndex += IndexMove
if BrightnessIndex > %MaxIndex%
BrightnessIndex := MaxIndex
if BrightnessIndex < 0
BrightnessIndex := 0
NewBrightness := NumGet(SupportedBrightness, BrightnessIndex, "UChar")
NumPut(0x03, Brightness, 0, "UChar") ; 0x01 = Set AC, 0x02 = Set DC, 0x03 = Set both
NumPut(NewBrightness, Brightness, 1, "UChar") ; The AC brightness level
NumPut(NewBrightness, Brightness, 2, "UChar") ; The DC brightness level
DllCall("DeviceIoControl"
, UInt, hLCD
, UInt, (DevVideo<<16 | 0x127<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS
, UInt, &Brightness
, UInt, 3
, UInt, 0
, UInt, 0
, UInt, 0
, Uint, 0)
DllCall("CloseHandle", UInt, hLCD)
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Close application by scroll wheel click from taskbar
ShouldActivateMButton() {
MouseGetPos, xpos, ypos, , ControlUnderMouse
return ControlUnderMouse = "MSTaskSwWClass1"
|| ControlUnderMouse = "ApplicationManager_DesktopShellWindow"
|| ControlUnderMouse = "Shell_TrayWnd1"
|| ControlUnderMouse = "MSTaskListWClass1"
}
#If ShouldActivateMButton()
MButton::
Send +{RButton}
WinWait ahk_class #32768,, 1 ; Menu
if !ErrorLevel
Send c ; Close
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment