help with evilC's UCR scripting

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

help with evilC's UCR scripting

27 Apr 2017, 05:32

hey guys can anyone help me with scripting in evilC's UCR https://autohotkey.com/boards/viewtopic.php?t=12249 ?

my problem is repeating the script

i have a script with button sequence: LEFT, LEFT, DOWN, LEFT so if i press binded key it works correctly but if i hold binded key there are a small pause between 1rst and 2nd sequences it looks like:
LEFT, LEFT, DOWN, LEFT, !!!PAUSE!!!, LEFT, LEFT, DOWN, LEFT, LEFT, LEFT, DOWN, LEFT, etc

can u pls help me with deleating that pause

here is my script

Code: Select all

class test1 extends _Plugin {
	Type := "test1"
	Description := "Your description here"
	; The Init() method of a plugin is called when one is added. Use it to create your Gui etc
	Init(){
		; Create the GUI
		; Add a hotkey, and give it the name "MyHk1". All hotkey objects can be accessed via this.InputButtons[name]
		; Have it call MyHkChangedState when it changes state.
		this.AddInputButton("IB1", 0, this.MyHkChangedState.Bind(this), "xm ym w200")
		; Add an Output, and give it the name "MyOp1". All output objects can be accessed via this.OutputButtons[name]
		this.AddOutputButton("OB6", 0, "xm yp+25 w200")
		this.AddOutputAxis("OutputAxis1", 0, "xm yp+25 w125")
		this.AddOutputAxis("OutputAxis2", 0, "xm yp+25 w125")
	}
 
	; Called when the hotkey changes state (key is pressed or released)
	MyHkChangedState(e){
			if (e){	; Only do this on press of the Input Button (e=1), do nothing on release (e=0)
			static StickOps := UCR.Libraries.StickOps
			; The input button was pressed, send the sequence of actions

			; X Axis Back
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(0))	
			Sleep 25
			; X Axis Centre
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
			Sleep 25
			; X Axis Back
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(0))
			Sleep 25
			; X Axis Centre
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
			Sleep 100
			; Y Axis Down
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(100))
			Sleep 25
			; X Axis Back
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(0))
			Sleep 25
			; X Axis Centre
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
			; Y Axis Centre
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(50))
			
	} else {
			; X Axis Centre
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
			; Y Axis Centre
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(50))

		}
	}

}
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: help with evilC's UCR scripting

27 Apr 2017, 08:57

You should probably post requests for support with UCR on the UCR thread - that way I get notified via email...

You are using a button as the input.
When you hold a button, it repeats.

ie, if you hold the input button, then MyHkChangedState repeatedly gets called with the value 1

So your code is starting the sequence over and over most likely.

This behavior is configurable - where you bind the input button, drop down the list and select "Suppress Repeats"
Image

You could also add code like this to your plugin to enforce repeat suppression even if the user has not selected it:

Code: Select all

Init(){
	this.CurrentState := 0
	;rest of code here
}

MyHkChangedState(e){
	if (e == this.CurrentState)
		return
	this.CurrentState := e
	; Rest of code here
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: help with evilC's UCR scripting

27 Apr 2017, 09:04

tnx a lot for answer. i'll try it later
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: help with evilC's UCR scripting

28 Apr 2017, 01:25

hmm this code just stops the repeating after 1rst sequence - this is not exactly what i need

may be the pause between 1rst and 2nd sequences goes because of my old version of UCR ? i am using 0.0.7 version instead the latest 0.1.13

can i simply copy n paste my plugins from old version to new or i need to edit something in it ? sorry i cant check it now myself :(
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: help with evilC's UCR scripting

28 Apr 2017, 03:43

You cannot copy paste your code to the latest UCR versions, you can read the wiki on UCR plugin development.

Maybe you need to use SetTimer, eg,

Code: Select all

MyHkChangedState(e){
	if (e == this.CurrentState)
		return
	; It has to be more elaborate than this, this is just a hint.
	if e
		SetTimer,doTheStuff,10
	else
		SetTimer,doTheStuff, off
	this.CurrentState := e
	return
}
More hints on using SetTimer can be found in the ButtonsToAxisSoft plugin, in the newer versions.

Good luck.
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: help with evilC's UCR scripting

28 Apr 2017, 06:21

tnx for answer

i see that old functions like "StickOps" are still working in new version of UCR, so i think i need a little fixes in my old plugins to work with new UCR, for example creating GUI is different and "this.OutputAxes" is "this.OutputAxis" now

so first of all i'll try to rewrite my plugins n run them on newest UCR, then i'll back to pauses ;)
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: help with evilC's UCR scripting

28 Apr 2017, 11:03

so guys i tried to rewrite one of my plugins here is the code

Code: Select all

class test1 extends _UCR.Classes.Plugin {
	Type := "test1"
	Description := "Your description here"
	Init(){
		Gui, Add, GroupBox, Center xm ym w170 h60 section, Input Button
		this.AddControl("InputButton", "IB1", 0, this.ButtonInput.Bind(this, 1), " xs+5 yp+15")
		this.AddControl("ButtonPreviewThin", "", 0, this.IOControls.IB1, "x+0 yp")
		
		Gui, Add, GroupBox, Center x190 ym w60 h30 section, Output Button
		this.AddControl("OutputAxis", "OA1", 0, "xs+5 yp+15")
		this.AddControl("AxisPreview", "", 0, this.IOControls.OA1, "x+0 yp", 50)
		this.AddControl("OutputAxis", "OA2", 0, "x+5 yp")
		this.AddControl("AxisPreview", "", 0, this.IOControls.OA1, "x+0 yp", 50)
	}
	
	MyHkChangedState(e){
			if (e){	; Only do this on press of the Input Button (e=1), do nothing on release (e=0)
			static StickOps := UCR.Libraries.StickOps
			; The input button was pressed, send the sequence of actions

			; X Axis Back
			this.OutputAxis.OA1.SetState(StickOps.AHKToVjoy(0))	
			Sleep 25
			; X Axis Centre
			this.OutputAxis.OA1.SetState(StickOps.AHKToVjoy(50))
			Sleep 25
			; X Axis Back
			this.OutputAxis.OA1.SetState(StickOps.AHKToVjoy(0))
			Sleep 25
			; X Axis Centre
			this.OutputAxis.OA1.SetState(StickOps.AHKToVjoy(50))
			Sleep 100
			; Y Axis Down
			this.OutputAxis.OA2.SetState(StickOps.AHKToVjoy(100))
			Sleep 25
			; X Axis Back
			this.OutputAxis.OA1.SetState(StickOps.AHKToVjoy(0))
			Sleep 25
			; X Axis Centre
			this.OutputAxis.OA1.SetState(StickOps.AHKToVjoy(50))
			; Y Axis Centre
			this.OutputAxis.OA2.SetState(StickOps.AHKToVjoy(50))
			
	} else {
			; X Axis Centre
			this.OutputAxis.OA1.SetState(StickOps.AHKToVjoy(50))
			; Y Axis Centre
			this.OutputAxis.OA2.SetState(StickOps.AHKToVjoy(50))

		}
	}

}
 
 

so i get no errors on startup and can add my plugin in UCR and bind input button and output axes like this

Image

but when i press input button ("q" im my case) nothing happens :(

what i do wrong guys ?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: help with evilC's UCR scripting

28 Apr 2017, 11:21

this.AddControl("InputButton", "IB1", 0, this.ButtonInput.Bind(this, 1), " xs+5 yp+15")
There is no function called ButtonInput

Your main processing function is called MyHkChangedState

Furthermore, MyHkChangedState accepts only one parameter.
So you probably want: this.AddControl("InputButton", "IB1", 0, this.MyHkChangedState.Bind(this), " xs+5 yp+15")
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: help with evilC's UCR scripting

28 Apr 2017, 11:54

yep now input button fires correctly put output axes still not work at all :(

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], joedf, MiM, scriptor2016, supplementfacts and 142 guests