If button pressed do one thing, if not - do another! Help me to improve script please

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
uNseen
Posts: 26
Joined: 16 Sep 2016, 06:12

If button pressed do one thing, if not - do another! Help me to improve script please

24 Jun 2018, 12:21

Hi!

In the game i play if i press some Button alone then it does one thing, if i press Shift+Button, then it's another thing.

I have a script:

Code: Select all

*Rbutton::
{
    Sendinput, {d down}{Shift down}{Click down}{z down}
    keywait, Rbutton
    Sendinput, {d up}{Shift up}{Click up}{z up}
}
Return
When i hold RButton and need to press another button (for example 1), i need it to be pressed without Shift, OR with imitation of {shift up} and then quickly {shift down} (so that it doesn't break shift state of RButton script). I wrote a simple script to do this:

Code: Select all

*1::
{
    Sendinput, {Shift up}{1 down}
    keywait, 1
    Sendinput, {Shift down}{1 up}
}
Return
^This way^ im able to press 1 without breaking Shift state from script linked to RButton. However when i press 1 alone (and RButton is not pressed) i end up with pressed shift.

Could you help me to combine these 2 scripts so that if RButton script is executed then other buttons are pressed without shift?
Or something like If Rbutton is pressed Then one script executed Else another.
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: If button pressed do one thing, if not - do another! Help me to improve script please

25 Jun 2018, 01:31

Hallo,
try:

Code: Select all

*RButton::
Sendinput, {d down}{Shift down}{Click down}{z down}
Loop
{
	Input, Key, L1
	Key := GetKeyName(Key)
	Sendinput, {Text}%Key%
}
Until (ErrorLevel = "NewInput")
Return
*RButton Up::
Input
Sendinput, {d up}{Shift Up}{Click up}{z up}
Return
uNseen
Posts: 26
Joined: 16 Sep 2016, 06:12

Re: If button pressed do one thing, if not - do another! Help me to improve script please

25 Jun 2018, 10:22

@Rohwedder

Tried your script. When i release (unpress) Rbutton i keep staying in shift mode.

Maybe i should have mentioned that in 90% of the time when i need to use script i need RButton to be pressed down, not single clicking.
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: If button pressed do one thing, if not - do another! Help me to improve script please

26 Jun 2018, 02:26

Hallo,
It worked here.
I have modified the script a little bit with now three different {Shift Up}.
Hope it helps.

Code: Select all

*RButton::
Sendinput, {d down}{Shift down}{Click down}{z down}
Loop
{
	Input, Key, L1
	Key := GetKeyName(Key)
	Sendinput, {Text}%Key%
}
Until (ErrorLevel = "NewInput")
Sendinput, {Shift Up}
Sendinput, {d up}{Click up}{z up}
Sendinput, {LShift Up}{RShift Up} ;just in case
Return
*RButton Up::Input
uNseen
Posts: 26
Joined: 16 Sep 2016, 06:12

Re: If button pressed do one thing, if not - do another! Help me to improve script please

26 Jun 2018, 03:38

@Rohwedder

It doesn't work :) Have you tried it yourself? Run the script any where, click right button and then you'll see that you stay in Shift-locked mode. Open Word / notepad and type some letters.
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: If button pressed do one thing, if not - do another! Help me to improve script please

26 Jun 2018, 03:50

Hallo,
of course I tested it in Notepad, Notepad++ and Word!
Both scripts function here.
Windows 7 Enterprise, Autohotkey run as admin

Use https://autohotkey.com/docs/commands/KeyHistory.htm for debugging.
uNseen
Posts: 26
Joined: 16 Sep 2016, 06:12

Re: If button pressed do one thing, if not - do another! Help me to improve script please

26 Jun 2018, 04:14

@Rohwedder

Sorry, with your last script it was my fault. I didn't see scrollbar and copied an incomplete textcode. When using last script there's indeed no shift-locking after releasing Rbutton, however... when using script, button 1 still acts like it is in shift mode, and also i have weird things happening when i press other buttons during script (like tab). Tab in my game activates map, whereas when i use script and press tab i receive multiple menu opening in the game, instead of opening / closing map. There's no such thing when i use my initial script.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Freddie, haomingchen1998, mmflume, scriptor2016, ShatterCoder and 91 guests