Advice on blockinput not working? Could really use some help.

Ask gaming related questions
Elish
Posts: 5
Joined: 23 Dec 2020, 23:37

Advice on blockinput not working? Could really use some help.

Post by Elish » 23 Jan 2021, 21:43

Ive been trying to figure this out for awhile, I am running as admin, and I am compiling into an exe file.

What I am trying to do: I am trying to momentarily block RButton on mouse for 100MS and then return RButton to the exact state it was in before I blocked imput from it. I am trying to block it when either the 1 2 or 3 key is pressed on my keyboard. So I press 2, it will momentarily block RButton and run a simple keypress macro. Here is the code I have.

Code: Select all

2WasPressedAt:=A_TickCount-100
~*2::2WasPressedAt:=A_TickCount
#if A_TickCount-2WasPressedAt<100
~RButton::return ; Should suspend Rbutton for 100MS

~2::           ;                    Macro to be run when 2 is pressed.
sleep 10
send, {~$2 down}       ; Should press 2 in program but not activate macro again
send, {~$2 up}           ; Should release 2 in program but not activate macro again
sleep 10
send, {5 down}
sleep 60
send, {5 up}
sleep 60
send, {4 down}
sleep 60
send, {4 up}
sleep 60
send, {6 down}
sleep 60
send, {6 up}
return
[Mod edit: [code][/code] tags added.]

I feel like I am close to getting this to work, any help appriciated. The sequence of events that I am trying to accomplish would look like this.

I am holding down Rbutton, as soon as I press either 1 2 or 3 on keyboard, it will momentaraly disable RButton, send the key (either 1 2 or 3) to the program window, return RButton to the pressed position because I haven't taken my finger off the RButton, so it would be in the same state it was in before I pressed 1 2 or 3, and it also activates the macro listed above. Im not sure if I need to be using #blockinput on/off or what I am missing.

Sorry if this is confusing, ive been working on this for awhile and have been learning this software for about a month now, I have no programming experience as I am sure you can tell =)

Any help appriciated, thank you.
Last edited by gregster on 24 Jan 2021, 18:03, edited 2 times in total.
Rohwedder
Posts: 3947
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Advice on blockinput not working? Could really use some help.

Post by Rohwedder » 24 Jan 2021, 03:41

Hallo,
try:

Code: Select all

$2:: ; Macro to be run when 2 is pressed.
RBlock(100) ;suspend and release Rbutton for 100ms     
sleep 10
send, {2 down} ; press 2 in program but not activate macro again
send, {2 up}   ; release 2 in program but not activate macro again
sleep 10
send, {5 down}
sleep 60
send, {5 up}
sleep 60
send, {4 down}
sleep 60
send, {4 up}
sleep 60
send, {6 down}
sleep 60
send, {6 up}
return


#If RBlock
RButton::Return
#If
RBlock(Time)
{
	Global
	SetTimer, RBlockEnd,% -Time
	RBlock := True
	IF GetKeyState("RButton","P")
		Send, {RButton Up}
	Return
	RBlockEnd:
	RBlock := False
	IF GetKeyState("RButton","P")
		Send, {RButton Down}
	Return
}
Elish
Posts: 5
Joined: 23 Dec 2020, 23:37

Re: Advice on blockinput not working? Could really use some help.

Post by Elish » 24 Jan 2021, 12:55

it seems to be working perfectly, let me play around with it some more and make sure im not dreaming =) thank you so much for the help very much appriciated!
Elish
Posts: 5
Joined: 23 Dec 2020, 23:37

Re: Advice on blockinput not working? Could really use some help.

Post by Elish » 24 Jan 2021, 14:13

Rohwedder wrote:
24 Jan 2021, 03:41
Hallo
Is there a list of commands like RBlock, that aren't listed on the ahk website? It works perfectly but I searched for the command in the ahk library and it never came up. Is there a list of shortcut commands like this one somewhere online?
User avatar
Spawnova
Posts: 455
Joined: 08 Jul 2015, 00:12
Contact:

Re: Advice on blockinput not working? Could really use some help.

Post by Spawnova » 24 Jan 2021, 17:59

Elish wrote:
24 Jan 2021, 14:13
Is there a list of commands like RBlock, that aren't listed on the ahk website? It works perfectly but I searched for the command in the ahk library and it never came up. Is there a list of shortcut commands like this one somewhere online?

That is a custom function it is located at the bottom of the script. Custom Functions are very useful and can help the readability in scripts a lot.

You can make your own as well, here's an example:

Code: Select all

;this is how you normally get a random value
random,result1,1,100

;with a custom function it can be even easier
result2 := Random(1,100)

msgbox % result1 ", " result2
exitapp



;declaring a custom function here
;assigning a parameter a value here means if you call this function -
;and there was no second paramater supplied it defaults to 100 in this case
Random(min,max=100) {   
	random,result,% min,% max
	return result
}
Some of my AHK programs: 3D Voxel Game - Platformer Game - Langton's Ant - Raycast light/Pixel Water - Creating HD map of any game
Or check out my Youtube for these plus many more projects! :D
Post Reply

Return to “Gaming”