Skip to content

Instantly share code, notes, and snippets.

@dsetareh
Created July 1, 2021 22:22
Show Gist options
  • Save dsetareh/1dbf9c281daf5f1f5f97bdfc14f3ec81 to your computer and use it in GitHub Desktop.
Save dsetareh/1dbf9c281daf5f1f5f97bdfc14f3ec81 to your computer and use it in GitHub Desktop.
osrs mouse ahk with toggle between shift and esc
SendShift = 1
SendShift := SendShift = 1 ? 0 : 1
SetTimer, FollowMouse, 8 ; 120hz idk
SetTimer, RemoveToolTip, -2000
XButton2::
if (SendShift = 1) {
HoldShift()
}
else {
HoldEsc()
}
return
HoldShift() {
Send, {Shift Down}
KeyWait, XButton2
Send, {Shift Up}
}
HoldEsc() {
Send, {Esc Down}
KeyWait, XButton2
Send, {Esc Up}
}
XButton1::
Send, {Space Down}
KeyWait, XButton1
Send, {Space Up}
return
NumpadAdd::
SendShift := SendShift = 1 ? 0 : 1
SetTimer, FollowMouse, 30
SetTimer, RemoveToolTip, -2000
return
FollowMouse:
ToolTipFM(SendShift = 1 ? "Sending Shift!" : "Sending Esc!")
return
RemoveToolTip:
SetTimer, FollowMouse, off
ToolTipFM() ; destroy tooltip
return
ToolTipFM(Text="", WhichToolTip=16, xOffset=16, yOffset=16) { ; ToolTip which Follows the Mouse
static LastText, hwnd, VirtualScreenWidth, VirtualScreenHeight ; http://www.autohotkey.com/forum/post-430240.html#430240
if (VirtualScreenWidth = "" or VirtualScreenHeight = "")
{
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
}
if (Text = "") ; destroy tooltip
{
ToolTip,,,, % WhichToolTip
LastText := "", hwnd := ""
return
}
else ; move or recreate tooltip
{
CoordMode, Mouse, Screen
MouseGetPos, x,y
x += xOffset, y += yOffset
WinGetPos,,,w,h, ahk_id %hwnd%
; if necessary, adjust Tooltip position
if ((x+w) > VirtualScreenWidth)
AdjustX := 1
if ((y+h) > VirtualScreenHeight)
AdjustY := 1
if (AdjustX and AdjustY)
x := x - xOffset*2 - w, y := y - yOffset*2 - h
else if AdjustX
x := VirtualScreenWidth - w
else if AdjustY
y := VirtualScreenHeight - h
if (Text = LastText) ; move tooltip
DllCall("MoveWindow", A_PtrSize ? "UPTR" : "UInt",hwnd,"Int",x,"Int",y,"Int",w,"Int",h,"Int",0)
else ; recreate tooltip
{
; Perfect solution would be to update tooltip text (TTM_UPDATETIPTEXT), but must be compatible with all versions of AHK_L and AHK Basic.
; My Ask For Help link: http://www.autohotkey.com/forum/post-421841.html#421841
CoordMode, ToolTip, Screen
ToolTip,,,, % WhichToolTip ; destroy old
ToolTip, % Text, x, y, % WhichToolTip ; show new
hwnd := WinExist("ahk_class tooltips_class32 ahk_pid " DllCall("GetCurrentProcessId")), LastText := Text
%A_ThisFunc%(Text, WhichToolTip, xOffset, yOffset) ; move new
}
Winset, AlwaysOnTop, on, ahk_id %hwnd%
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment