Scroll to change items in ARK.

Ask gaming related questions
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Scroll to change items in ARK.

16 Jan 2018, 11:03

Hi all,

I had noticed that there were no posts on an easy way to do this, so for the community I would like to share this code. It allows your scroll wheel to change items in ARK, or other games really, the same way it does in Minecraft. If there are any suggested edits please make them and post!

Code: Select all

;------------ ARK: Survival Evolved -----------------

WheelUp::
IfWinActive, ARK: Survival Evolved 
{
    if (ARKSCROLL < 9) 
    {
        ARKSCROLL := ARKSCROLL + 1
        sleep, 10
        send, %ARKSCROLL%
            Return
    }
    if (ARKSCROLL >= 9) 
    {
        ARKSCROLL = 0
        sleep, 10
        send, %ARKSCROLL%
            Return
    }
    Return
}
IfWinNotActive, ARK: Survival Evolved
send, {WheelUp}
    Return

WheelDown::
IfWinActive, ARK: Survival Evolved 
{
    if (ARKSCROLL > 0)
    {
        ARKSCROLL := ARKSCROLL - 1
        sleep, 10
        send, %ARKSCROLL%
            Return
    }
    if (ARKSCROLL <= 0)
    {
        ARKSCROLL = 9
        sleep, 10
        send, %ARKSCROLL%
            Return
    }
        Return
}
IfWinNotActive, ARK: Survival Evolved 
send, {WheelDown}
    Return
User avatar
evilC
Posts: 4344
Joined: 27 Feb 2014, 12:30

Re: Scroll to change items in ARK.

18 Jan 2018, 07:07

1) Put the IfWinActive line before the hotkey line. If you did this, you would not need the IfWinNotActive to send WheelUp, as the block simply would not happen if the app was not active.

Code: Select all

WheelUp::
IfWinActive, ARK: Survival Evolved 
2) If this is a finished script, put it in the "Scripts and Functions" forum

3) This code seems a little off...

Code: Select all

    if (ARKSCROLL < 9) 
    {
        ARKSCROLL := ARKSCROLL + 1
        sleep, 10
        send, %ARKSCROLL%
            Return
    }
    if (ARKSCROLL >= 9) 
    {
        ARKSCROLL = 0
        sleep, 10
        send, %ARKSCROLL%
            Return
    }
Is the intention that this code only sends 1-8? It looks like you are maybe trying to send 1-9, but this code will never send 9.
It also needlessly repeats logic and send code, you only need one send and one sleep - just make sure you increment and do the wrap-around before you hit that point, like so:

Code: Select all

	ARKSCROLL++			; A shorthand way of saying ARKSCROLL := ARKSCROLL + 1
	if (ARKSCROLL > 9){
		ARKSCROLL := 0
	}
	sleep, 10				; Not too sure why you would want to sleep BEFORE sending the key?
	send, %ARKSCROLL%
	Return
Last edited by evilC on 19 Jan 2018, 16:57, edited 1 time in total.
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Re: Scroll to change items in ARK.

19 Jan 2018, 15:08

1) Thanks for that I was thinking it would work but tested the other route just in case. (which is less efficient, but could come in handy for other things, and as is if I am holding shift it does not change to other weapons on me if I am running.)

2) It was and it wasn't, as you found there were areas that could have been improved.

3. Its 0-9 not 1-9, but I can confirm it does hit 9 as the code currently is in the initial post.

I will have to look into if that changes using "IfWinActive" before the wheel up instead of the after, or if it will effect everything behind it in my usual running scrip or return properly.
User avatar
evilC
Posts: 4344
Joined: 27 Feb 2014, 12:30

Re: Scroll to change items in ARK.

19 Jan 2018, 16:53

TrippyHippyDan wrote: 3. Its 0-9 not 1-9, but I can confirm it does hit 9 as the code currently is in the initial post.
Yeah, sorry, I obviously mis-read it, but it is still not doing what you think it is ;)
It does 1 to 0, with the 9th iteration sending both 9 and 0
Your code, with sends replaced with logging:

Code: Select all

#SingleInstance force
ARKSCROLL := 0
output := ""

Loop 10
{
    if (ARKSCROLL < 9) 
    {
        ARKSCROLL := ARKSCROLL + 1
        output .= "Iteration # " A_Index ": " ARKSCROLL "`n"
    }
    if (ARKSCROLL >= 9) 
    {
        ARKSCROLL = 0
        output .= "Iteration # " A_Index ": " ARKSCROLL "`n"
    }
}
clipboard := output
msgbox % output
Result (Iteration 9 would have done 2 sends because you used if, not else if)
Iteration # 1: 1
Iteration # 2: 2
Iteration # 3: 3
Iteration # 4: 4
Iteration # 5: 5
Iteration # 6: 6
Iteration # 7: 7
Iteration # 8: 8
Iteration # 9: 9
Iteration # 9: 0
Iteration # 10: 1

My code:

Code: Select all

#SingleInstance force
ARKSCROLL := 0
output := ""

Loop 10
{
	ARKSCROLL++			; A shorthand way of saying ARKSCROLL := ARKSCROLL + 1
	if (ARKSCROLL > 9){
		ARKSCROLL := 0	; Changing this to 1 will make it send 1-9 instead of wrapping around to 0
	}
	output .= "Iteration # " A_Index ": " ARKSCROLL "`n"
}

clipboard := output
msgbox % output

Result:
Iteration # 1: 1
Iteration # 2: 2
Iteration # 3: 3
Iteration # 4: 4
Iteration # 5: 5
Iteration # 6: 6
Iteration # 7: 7
Iteration # 8: 8
Iteration # 9: 9
Iteration # 10: 0
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Re: Scroll to change items in ARK.

19 Jan 2018, 17:30

@evilC Thanks for that. I had't been using anything in slot 0 or 9 enough to notice it yet, but it defiantly could have gotten annoying!
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Re: Scroll to change items in ARK.

19 Jan 2018, 17:46

@evilC Still working on this further because I want to go from 1 - 0 and then if I keep scrolling up go back through the list, but with your help this does it and there are no doubles scrolling up or down!

Code: Select all

SetTitleMatchMode, 2
ARKSCROLL := 0
;------------ ARK: Survival Evolved -----------------


#IfWinActive, ARK: Survival Evolved 
WheelUp::
{
    if (ARKSCROLL < 9) 
    {
        ARKSCROLL := ARKSCROLL + 1
        sleep, 10
        send, %ARKSCROLL%{Enter}
            Return
    }
    if (ARKSCROLL >= 9) 
    {
        ARKSCROLL = 0
        sleep, 10
        send, %ARKSCROLL%{Enter}
            Return
    }
    Return
}
	Return


#IfWinActive, ARK: Survival Evolved
WheelDown::
{
    if (ARKSCROLL >= 1)
    {
        ARKSCROLL := ARKSCROLL - 1
        sleep, 10
        send, %ARKSCROLL%{Enter}
            Return
    }
    if (ARKSCROLL <= 0)
    {
        ARKSCROLL = 9
        sleep, 10
        send, %ARKSCROLL%{Enter}
            Return
    }
        Return
}
    Return
User avatar
evilC
Posts: 4344
Joined: 27 Feb 2014, 12:30

Re: Scroll to change items in ARK.

19 Jan 2018, 19:04

As I said, replace your two IF statements with the way I do it.
You get the same result, and it is WAY more elegant.
Having the send in two places when you not need to makes the code harder to maintain and understand.
Hell, you do not even need to repeat the same code for wheel up and down, you can do the whole lot with one function

Code: Select all

WheelUp::
	DoSend(1)
	return

WheelDown::
	DoSend(-1)
	return

DoSend(dir){
	global ARKSCROLL				; static ARKSCROLL would also work
	ARKSCROLL := ARKSCROLL + dir		; Works for positive and negative! 2 plus -1 is 1 !!
	if (ARKSCROLL > 9){
		ARKSCROLL := 0
	} else if (ARKSCROLL < 0){
		ARKSCROLL := 9
	}
	Send %ARKSCROLL%{Enter}
}
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Re: Scroll to change items in ARK.

19 Jan 2018, 20:06

@evilC

That is a lot cleaner and looking closer to python than AHK. (AHK the deeper I get into it feels more and more like a mixed bag of other languages @.@) Thanks much I didn't know you could define objects so that was a huge help!

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 9 guests