Skip to content

Instantly share code, notes, and snippets.

@emvaized
Last active June 19, 2023 05:36
Show Gist options
  • Save emvaized/b7fc604bb6571d7958f642e60556819b to your computer and use it in GitHub Desktop.
Save emvaized/b7fc604bb6571d7958f642e60556819b to your computer and use it in GitHub Desktop.
Autohotkey script to emulate Linux/MacOS context menu behavior in Windows 11
; Make Windows context menu behave like in MacOS/Linux
; In Linux and MacOS, context menu is revealed on right mouse down event, allowing user to continue moving the cursor,
; higlight any menu entry, and then select it by releasing the right mouse key.
; This script emulates similar behavior in Windows. Tested only in Windows 10/11.
; Note: It may interfere with some games which rely on right mouse button.
; Therefore added simple fullscreen-app check to not run the mouse listener
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
RightButtonIsHeld := false
#If !isWindowFullScreen("A")
RButton::
{
Click, Right
MouseGetPos, MouseXPos, MouseYPos
KeyWait, RButton, T0.2 ; waits for 0.2 seconds to count just as right click
if(ErrorLevel)
{
;button held down
RightButtonIsHeld := true
} else {
;ignore mouse up
RightButtonIsHeld := false
}
return
}
RButton Up::
{
if (RightButtonIsHeld == true) {
; select the highlighted entry
MouseGetPos, MouseNewXPos, MouseNewYPos
if !(MouseNewXPos == MouseXPos) && !(MouseNewYPos == MouseYPos)
{
Click
}
} else {
; regular menu show, nothing to select
}
RightButtonIsHeld := false
}
; disable script in games
isWindowFullScreen(winTitle) {
;source: https://www.autohotkey.com/board/topic/38882-detect-fullscreen-application/
WinGet style, Style, ahk_id %WinID%
WinGetPos ,,,winW,winH, %winTitle%
; 0x800000 is WS_BORDER.
; 0x20000000 is WS_MINIMIZE.
; no border and not minimized
Return ((style & 0x20800000) or winH < A_ScreenHeight or winW < A_ScreenWidth) ? false : true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment