LButton Up issue, eat mouse press?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

LButton Up issue, eat mouse press?

31 Dec 2016, 22:28

E.g. on Notepad, a script to prevent clicking on a context menu.

Capture a mouse release (an LButton up).
The user holds down the mouse over the File item, drags down over the Open item, and releases the mouse button, at that point, if the window under the cursor is a context menu, I want that click to be eaten, the user should not be able to click on the menu, LButton Up has not happened yet, because that triggers the hotkey, (so the computer views the mouse button as still being held down,) so LButton Up will have to be sent somewhere I suppose, somewhere where it will have no effect.

Capture a mouse press (an LButton down).
The other possibility which is dealt with, is: the user clicks File (a down and up motion, where the mouse button is released), the menu appears, (the cursor is moved down but not dragged,) the user clicks on the Open menu item, here the down press is captured, rather than the up release.

===============

Apologies for what I think is a classic issue, but that I'm having trouble resolving/finding answers to on the forum.
LButton works fine, but not LButton Up.
The idea is to stop context menus being clicked on.
The final script actually blocks access to only one individual menu item.

I think the issue is that I need to 'eat' an LButton Up,
and the only ideas I have are to move the cursor to click somewhere 'safe',
that is not the menu, or to click onto an AutoHotkey GUI window/control, I don't know if sending a Click command somewhere will be of use.

[EDIT: btw how does WinMenuSelectItem invoke items, is it by grabbing the item ID, and using PostMessage/SendMessage, or is there some specific way to *press* the button]

;===============

Code: Select all

#IfWinActive, ahk_class Notepad
;works
LButton::
MouseGetPos, , , hWnd
WinGetClass, vWinClass, ahk_id %hWnd%

if vWinClass in #32768
{
MsgBox can't click me!
Return
}

SendInput {LButton Down}
KeyWait, LButton
SendInput {LButton Up}
Return

;===============

;not working
LButton Up::
MouseGetPos, , , hWnd
WinGetClass, vWinClass, ahk_id %hWnd%

if vWinClass in #32768
{
MsgBox can't click me!
SendInput {LButton Up}
Return
}

SendInput {LButton Up}
Return
#IfWinActive

;===============
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: LButton Up issue, eat mouse press?

01 Jan 2017, 12:46

OK, I have a working script, there is just one line which could be improved if people have any good ideas.

How to do a 'safe click up discharge'?
Currently I have:

Code: Select all

ControlSend, Dummy, {Click, 0, 0}, ahk_class Notepad

Code: Select all

#IfWinActive, ahk_class Notepad
LButton::
CoordMode, Mouse, Screen
MouseGetPos, , , hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
ToolTip DOWN %vWinClass%, 500, 200

if vWinClass in #32768
{
ToolTip, DOWN %vWinClass% blocked, 500, 200
Return
}

SendInput {LButton Down}
KeyWait, LButton

MouseGetPos, vPosX, vPosY, hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
ToolTip UP %vWinClass%, 500, 200

if vWinClass in #32768
{
;do a safe click up discharge method 1
;Click 0, 0 up
;MouseMove, %vPosX%, %vPosY%

;do a safe click up discharge method 2
ControlSend, Dummy, {Click, 0, 0}, ahk_class Notepad

ToolTip UP %vWinClass% blocked, 500, 200
Return
}

SendInput {LButton Up}
Return
#IfWinActive
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], tatagi and 53 guests