Can't remap anything to RButton if other scripts run in parallel

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
blza
Posts: 18
Joined: 01 Sep 2015, 09:23
Contact:

Can't remap anything to RButton if other scripts run in parallel

01 Sep 2015, 09:48

Hello, I want to extend the functionality of mouse buttons in a way Adam Push's in Rocker.ahk made it http://lifehacker.com/257609/navigate-b ... ith-rocker.

I remember successfully using the original script but with the latest version (1.1.22.04) of Ahk it's somehow broken.

Cutting original script to it's bones I came to conclusion that I can't remap RButton to itself if other scripts are running in parallel.

So say, I have a the following simple script

Code: Select all

SendMode Input
RButton::	
	Send, {RButton}
	return
It works only if no other scripts are running in parallel. The standard right button context menu is shows. In that case I have the following in my Key History

Code: Select all

02  000	h	d	1.64	RButton        	
02  000	s	u	0.00	RButton        	
02  000	a	u	0.03	RButton        	
02  000	h	d	0.00	RButton        	
02  000	a	u	0.00	RButton     
If I run something as simple as

Code: Select all

$Numpad0::Enter
in another script file in parallel to the original script, the first one stops working and I have the following Key History for hitting Rbutton

Code: Select all

02  000	h	d	0.75	RButton        	
02  000	s	u	0.00	RButton        	
02  000	h	d	0.00	RButton        	
02  000	a	u	0.02	RButton  
It trouble concerns not only remapping of RButton to itself, if I add

Code: Select all

$a::	
	Send, {RButton}
	return	
it also will not work If second script is running in parallel.
For broken 'a' to 'RButton' case I'm having

Code: Select all

41  01E	h	d	0.38	a              	
02  000	h	d	0.00	RButton        	
02  000	a	u	0.01	RButton        	
02  000	h	d	0.00	RButton        	
02  000	a	u	0.02	RButton        	
41  01E	s	u	0.05	a      
If I exit all other scripts hitting 'a' will result in

Code: Select all

41  01E	h	d	1.34	a              	
02  000	a	u	0.05	RButton        	
02  000	h	d	0.00	RButton        	
02  000	a	u	0.00	RButton        	
41  01E	s	u	0.05	a       
Begging for your help, I'm totally stuck.
I definitely want to run other helper scripts in parallel, so putting them all into one file is not an options because of possible conflicts.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Can't remap anything to RButton if other scripts run in parallel

01 Sep 2015, 15:59

I can't reproduce your observations. Are you using some other software that modifies input, like mouse or keyboard driver applications?
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

01 Sep 2015, 21:22

I would expect this behaviour with SendMode InputThenPlay, but not SendMode Input. SendInput falls back to either SendEvent or SendPlay when you have another script which uses a hook (such as $Numpad0::Enter), and SendPlay typically does not work at all if UAC is enabled. UAC is typically always enabled on Windows 8 and later, with no option to fully disable it without breaking things. See also: EnableUIAccess.
blza
Posts: 18
Joined: 01 Sep 2015, 09:23
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 03:08

lexikos wrote:I would expect this behaviour with SendMode InputThenPlay, but not SendMode Input. SendInput falls back to either SendEvent or SendPlay when you have another script which uses a hook (such as $Numpad0::Enter), and SendPlay typically does not work at all if UAC is enabled. UAC is typically always enabled on Windows 8 and later, with no option to fully disable it without breaking things. See also: EnableUIAccess.
Seams that you are right.

Signing Autohotkey with EnableUIAccess and running scripts with 'Run with UI Access' does not help.

While playing with EnableUIAccess I learnt that long press of RButton while running another script works but not for all programs - it works for Task bar and Ahk icons in tray, but not for say TotalCommander. By contrast long press of 'a' does not work at all. I'm on Windows 7 x64 Pro as a local administrator, but it's an office notebook so different policies are applied by admins. So I guess UAC is in enabled.

Are there any other options left to make it work?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 06:14

Code: Select all

SendMode Input
RButton::	
	Send, {RButton}
	return
Are you aware / do you care that this code does not in fact "pass through" the right mouse button correctly?
On Rbutton down, this code sends Rbutton down, then RButton up.
When you release RButton, no up event is sent (it already got sent).

Maybe you want something like:

Code: Select all

RButton::
	Send, {RButton down}
	return

RButton up::	
	Send, {RButton up}
	return
I knocked up this quick Rock Mode test code, and cannot stop it working by running other scripts.

Code: Select all

#SingleInstance force
SendMode Input

lbutton_down := 0
rbutton_down := 0
RButton::
	rbutton_down := 1
	if (lbutton_down){
		Tooltip ROCK RIGHT
	}
	Send, {RButton down}
	return

RButton up::
	rbutton_down := 0
	Send, {RButton up}
	return

LButton::
	lbutton_down := 1
	if (rbutton_down){
		Tooltip ROCK LEFT
	}
	Send {LButton down}
	return
	
LButton up::
	lbutton_down := 0
	Send {LButton up}
	return
blza
Posts: 18
Joined: 01 Sep 2015, 09:23
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 08:25

evilC wrote: Are you aware / do you care that this code does not in fact "pass through" the right mouse button correctly?
Yes, I'm aware that my code is not fully functional, in particular it does not support right mouse button dragging. All I wanted to show with it is that It seem to block RButton events from system while other scripts run in parallel.
evilC wrote: I knocked up this quick Rock Mode test code, and cannot stop it working by running other scripts.
For me it shows appropriate tooltips for rocker gestures, but when other scripts run in parallel it also blocks all left and right mouse clicks. Long presses do not pass either.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 08:54

There's still the aspect of your key history showing more and different activity that is does for me (and like it should I think). Just to narrow down the cause of the problem, could you run the following:

Code: Select all

Run,Notepad.exe,,,PID
WinWaitActive,ahk_pid %PID%
SendInput SendInput works`n
SendEvent SendEvent works too!
My guess is the second line won't show up, regardless if it's the only script running.
blza
Posts: 18
Joined: 01 Sep 2015, 09:23
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 09:10

Nextron wrote:My guess is the second line won't show up, regardless if it's the only script running.
Every thing shows up regardless of parallel scripts running (tested with and without).
Even SendPlay works

Code: Select all

Run,Notepad.exe,,,PID
WinWaitActive,ahk_pid %PID%
SendInput SendInput works`n
SendEvent SendEvent works too!`n
SendPlay And even SendPlay works...
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 09:12

blza wrote:Long presses do not pass either.
My point being that testing "Long Press" is pointless, because your example code behaves no differently whether you issue a long or short press.
The fact that you are seeing different behavior to everyone else is certainly an indicator that there is something odd about your setup.
I know you tried the "Enable UI Access" code, but have you also tried running all the scripts as admin?
Not that I am suggesting that as a solution, just as an attempt to debug why this is happening.
blza
Posts: 18
Joined: 01 Sep 2015, 09:23
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 09:27

evilC wrote:The fact that you are seeing different behavior to everyone else is certainly an indicator that there is something odd about your setup.
I know you tried the "Enable UI Access" code, but have you also tried running all the scripts as admin?
Not that I am suggesting that as a solution, just as an attempt to debug why this is happening.
Just tried that with the same results :(
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

02 Sep 2015, 19:47

If you replace SendMode Input with the following, is there any change in behaviour with either one script or both scripts running?

Code: Select all

SendMode Event  ; (this is the default setting)
SetKeyDelay -1, 0
This is what I was referring to about SendInput:
Note: SendInput ignores SetKeyDelay because the operating system does not support a delay in this mode. However, when SendInput reverts to SendEvent under the conditions described below, it uses SetKeyDelay -1, 0 (unless SendEvent's KeyDelay is -1,-1, in which case -1,-1 is used). When SendInput reverts to SendPlay, it uses SendPlay's KeyDelay.

If a script other than the one executing SendInput has a low-level keyboard hook installed, SendInput automatically reverts to SendEvent (or SendPlay if SendMode InputThenPlay is in effect). This is done because the presence of an external hook disables all of SendInput's advantages, making it inferior to both SendPlay and SendEvent.
blza
Posts: 18
Joined: 01 Sep 2015, 09:23
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

03 Sep 2015, 05:10

lexikos wrote:If you replace SendMode Input with the following, is there any change in behaviour with either one script or both scripts running?

Code: Select all

SendMode Event  ; (this is the default setting)
SetKeyDelay -1, 0
Yes, it produces a lot of repetition of h, u, a, s Rbutton events in Key History for a single press, but with not much success: still Rbuttons passes mainly to taskbar and to tray icons and only with a long press.

I also tried to add SetMouseDelay, -1, 0, but it didn't help either.
Also tried to add

Code: Select all

#MaxThreadsPerHotkey 1
#MaxThreadsBuffer Off
but again with no results.

Some idea creeped into my mind and I ended up with the following code:

Code: Select all

RButton::
	Hotkey, RButton, RButton, Off
	Send, {Rbutton}
	Hotkey, RButton, RButton, On
	return
That alone works while other scripts are running. Still to add right-click dragging, but at least right-click works with it.

So can you tell me what a bummer I came into?
blza
Posts: 18
Joined: 01 Sep 2015, 09:23
Contact:

Re: Can't remap anything to RButton if other scripts run in parallel

03 Sep 2015, 05:23

And btw it produces strange results in Key history:
Sometimes it's just single

Code: Select all

02  000	h	d	0.56	RButton    
sometimes

Code: Select all

02  000	h	d	2.37	RButton        	
02  000	s	u	0.00	RButton    

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jeves, mikeyww and 292 guests