Trying to get this script down. All the googling I did tells me it's impossible but I feel like there MUST be a way.

Get help with using AutoHotkey and its commands and hotkeys
User avatar
CerpinTaxt
Posts: 13
Joined: 23 Dec 2017, 12:16

Trying to get this script down. All the googling I did tells me it's impossible but I feel like there MUST be a way.

23 Dec 2017, 12:57

I've been trying to get a script written for an embarrasingly long time and I somehow can't manage to get it right. I feel like a big dummy, soooo I'm crawling to you guys for help.

There's quite a few pretty specific detailed things that I wrote in my 'outline' that look like super simple things at first glance so I just want to make sure people read it fully instead of glancing at it and thinking it's one of the standard problems. Every thread I found on google had the same thing - somebody trying to accomplish this and then a bunch of people suggesting options which only allow for some of the results needed but not all of them.

I tried to write out what I want in the most logical way. The keys themselves are examples, but they're the keys I'm testing with. I plan to also use this for additional hotkeys once it gets ironed out.

Basically I want to be able to press RButton while holding down LButton to send a command. This works fine. But when I press RButton under these circumstances, I want it to only send this command and then I guess when I'm done I want it to reset the RButton without registering {Click, right, up} so it doesn't open a context menu. I'd like to do the same with holding down RButton and pressing LButton. (Remember, these are only examples.) I can get both of those requirements working BUT then it creates a new problem in that RButton doesn't do anything until I release it, which disables holding down RButton which I also need to work.

A lot of this is guessing based on a novice understanding so there's probably a better way to accomplish it but here is my best guess.

Since I need a hotkey to know the state of another key that was pressed before the hotkey itself, this is what I came up with. This is written as some weird pseudo-code since I'm trying to explain what I'm going for and I obviously don't know the exact code that would work. Don't take my formatting as gospel, this isn't how I write my actual .ahk code, this is just for this post lol.

Code: Select all

; ------------------------------------------------------------------------------------------------------------------------
; these variables need to constantly change between yes/no as corresponding keystate changes
; ------------------------------------------------------------------------------------------------------------------------
check if LButton is down
	assign var Left_Down := (yes|no)
	wait until LButton state changes again and chage value of Left_Down when it does

check if RButton is down
	assign var Right_Down := (yes|no)
	wait until RButton state changes again and chage value of Right_Down when it does

; ------------------------------------------------------------------------------------------------------------------------
; the actual hotkeys
; ------------------------------------------------------------------------------------------------------------------------
LButton::
		if Right_Down was 'no' upon LButton click
			Only activate initial {click} when this state is chosen upon initial LButton press	; don't want any left_Down clicking if I'm using the button as part of a hotkey and not a mouse button
			Otherwise act like normal mouse button until next LButton run
		
		
		if Right_Down was 'yes' when LButton first clicked
			do not send initial {Click, down}								
			upon every LButton click in this state
				send ^{PgUp}
				check Right_Down again
					if still 'yes' repeat above step (send & check)
					if it changed to 'no' end LButton hotkey

Return

RButton::
; ideally the following choice is made immediately so I don't have to wait to right click

		if Left_Down was 'no' when RButton first clicked
			Only activate {click, right_Down, down} when this state is chosen upon initial RButton press
			Only activate {click, right_Down, up} when RButton released in this state
			Act like normal mouse button until next RButton run, i.e. allow keeping RButton down for gestures etc

		if Left_Down was 'yes' when RButton first clicked
			do not send initial {Click, right, down}
			upon every RButton click in this state
				send ^{PgDn}
				check Left_Down again
					if still 'yes' repeat above step (send & check)
					if it changed to 'no' end RButton hotkey

Return
Last edited by CerpinTaxt on 23 Dec 2017, 20:47, edited 1 time in total.
Image
and with just one faint glance back into the sea
the mollusk lingers with its wandering eye
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Trying to get this script down. All the googling I did tells me it's impossible but I feel like there MUST be a way.

23 Dec 2017, 14:10

hard to understand what you are looking for, is this what you want?

Code: Select all

#if GetKeyState("RButton", "P")
$LButton::send ^{PgDn}
#if GetKeyState("LButton", "P")
$RButton::send ^{PgUp}
#if
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
lexikos
Posts: 6744
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Trying to get this script down. All the googling I did tells me it's impossible but I feel like there MUST be a way.

24 Dec 2017, 15:09

It's even easier than that.

Code: Select all

~RButton & LButton::Send ^{PgUp}
~LButton & RButton::Send ^{PgDn}
In your requirements you only mentioned blocking RButton while holding LButton and vice versa, not blocking both when used in combination. The problem with this type of combination is that if you don't block both buttons, one of the buttons will have some effect that you don't want. To solve that without a time machine means you have to block both buttons until you can determine that they aren't being used in combination.

In theory, one solution is to block either button when it is first pressed on its own and ...
  • if the second button is clicked, perform the corresponding action.
  • if the mouse moves, send a click down at the original position and replay the movement.
    Alternatively, it is possible to detect movement via a mouse hook and send the click down before the mouse movement comes into effect. However, mouse hooks aren't simple and they have the potential to make the mouse unusable if written incorrectly. Search keyword: WH_MOUSE_LL
  • if the button is released, send a click down and up.
My mouse gestures script uses a similar approach for drawing gestures with RButton, but I never really bothered with rocker gestures (i.e. combining the buttons as you want).

You can probably find other attempts at solving this issue by searching for "rocker gestures" on the forum.

Return to “Ask For Help”

Who is online

Users browsing this forum: brotherS, calipsoive, Google [Bot], StvSndr, Taurus, ystin and 186 guests