Detecting mouse button state when the ctrl key is pressed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Detecting mouse button state when the ctrl key is pressed

10 Mar 2019, 07:11

How do I detect if mouse buttons are being pressed/unpressed AFTER the modifier key is pressed down?
The native functions of the modifier and mouse buttons must be kept intack.

Code: Select all

~*LControl::
{
    mouse_state := GetKeyState("WheelDown") GetKeyState("WheelUp") GetKeyState("WheelLeft", "P") GetKeyState("WheelRight", "P") GetKeyState("XButton1", "P") GetKeyState("XButton2", "P") GetKeyState("LButton", "P") GetKeyState("RButton", "P") GetKeyState("MButton", "P")
    ToolTip % mouse_state
    return
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Detecting mouse button state when the ctrl key is pressed

10 Mar 2019, 09:35

Here is an example,

Code: Select all

#installmousehook ; need to install mouse hook for p option to work correctly.

buttons := ["XButton1", "XButton2", "LButton", "RButton", "MButton"]

~*LControl::
{
    mouse_state := "The following buttons are physically held down:`n`n"
    for k, button in buttons
		if getKeyState(button, "p")
			mouse_state .= button  "`n" 
	ToolTip % mouse_state
    return
}
Cheers.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Detecting mouse button state when the ctrl key is pressed

10 Mar 2019, 09:45

refactor as u see fit

Code: Select all

WheelDown := false
WheelUp := false
WheelLeft := false
WheelRight := false
XButton1 := false
XButton2 := false
LButton := false
RButton := false
MButton := false

/* maybe u want this instead?
~*LControl Up::
	LControl := false

	WheelDown := false
	WheelUp := false
	WheelLeft := false
	WheelRight := false
return
*/

~*LControl::
{
	LControl := true
	
	Sleep 1000
	ToolTip % WheelDown WheelUp WheelLeft WheelRight XButton1 XButton2 LButton RButton MButton 
	
	LControl := false

	WheelDown := false
	WheelUp := false
	WheelLeft := false
	WheelRight := false

	return
}

~*XButton1 Up::XButton1 := false
~*XButton2 Up::XButton2 := false
~*LButton Up::LButton := false
~*RButton Up::RButton := false
~*MButton Up::MButton := false

#If LControl
~*WheelDown::WheelDown := true
~*WheelUp::WheelUp := true
~*WheelLeft::WheelLeft := true
~*WheelRight::WheelRight := true
~*XButton1::XButton1 := true
~*XButton2::XButton2 := true
~*LButton::LButton := true
~*RButton::RButton := true
~*MButton::MButton := true
other than that, it makes no sense to be querying the wheel for its state. the notches dont have a "released" state

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mebelantikjaya and 333 guests