Universal Control Remapper (UCR) - v0.1.22 28th Oct 2018

Post gaming related scripts
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

15 Jan 2018, 15:53

@ evilC, I get this when I add the third point, with the code in this post
ucr.jpg
ucr.jpg (44.92 KiB) Viewed 4036 times
Cheers.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

15 Jan 2018, 16:00

OK, how about this?
Image

Code: Select all

class AxisToAxisDetent extends _UCR.Classes.Plugin {
	Type := "Remapper (Axis To Axis with Detent)"
	Description := "Maps an axis input to a virtual axis output (With Detent)"
	vAxis := 0
	vDevice := 0
	; Set up the GUI to allow the user to select input and output axes
	Init(){
		Gui, Add, GroupBox, % "xm w135 h130 section Center", Input Axis
		this.AddControl("InputAxis", "IA1", 0, this.MyInputChangedState.Bind(this), "xs+5 w125 y25")
		this.AddControl("AxisPreview", "", 0, this.IOControls.IA1, "xs+5 y+5 w125", 50)

		fn := this.UseCurrentClicked.Bind(this)
		Gui, Add, Button, hwndhwnd xs+5 y+5 w125, Copy Current >>>>
		GuiControl, +g, % hwnd, % fn

		Gui, Add, GroupBox, % "x155 ym w60 h130 section Center", Invert
		this.AddControl("CheckBox", "Invert", 0, "xs+25 w30 y40")
		
		Gui, Add, GroupBox, % "x225 ym w170 h130 section Center", Breakpoint settings
		this.SegmentManager := new this.SegmentControl(this.OnSegmentChanged.Bind(this), this, "xs+10 y25")
		
		Gui, Add, GroupBox, % "x400 ym w135 h130 section Center", Output Virtual Axis
		this.AddControl("OutputAxis", "OA1", this.MyOutputChangedValue.Bind(this), "xs+5 y25 w125")
		this.AddControl("AxisPreview", "", 0, this.IOControls.OA1, "xp y+5 w125", 50)
		
		Gui, Add, GroupBox, x540 ym w135 h130 section center, Settings String
		Gui, Add, Text, xs+5 y25, Copy this to another plugin`nof the same kind`nto duplicate settings
		this.AddControl("Edit", "Segments", this.OnSettingsLoad.Bind(this), "xs+5 y+10")
	}
	
	OnSegmentChanged(value){
		GuiControl, , % this.GuiControls.Segments.hwnd, % value
	}
	
	OnSettingsLoad(value){
		this.SegmentManager.LoadSettings(value)
	}
	
	UseCurrentClicked(){
		value := UCR.Libraries.StickOps.AHKToInternal(this.IOControls.IA1.Get())
		if (this.GuiControls.Invert.Get()){
			value := UCR.Libraries.StickOps.Invert(value)
		}
		value := UCR.Libraries.StickOps.InternalToAHK(value)
		this.SegmentManager.SetInputBox(value)
	}
	
	; The user changed options - store stick and axis selected for fast retreival
	MyOutputChangedValue(value){
		this.vAxis := value.Binding[1]
		this.vDevice := value.DeviceID
		this.OutputBound := value.IsBound()
	}
	
	; The user moved the selected input axis. Manipulate the output axis accordingly
	MyInputChangedState(value){
		value := UCR.Libraries.StickOps.AHKToInternal(value)
		if (this.OutputBound){
			if (this.GuiControls.Invert.Get()){
				value := UCR.Libraries.StickOps.Invert(value)
			}
			value := UCR.Libraries.StickOps.InternalToAHK(value)
			
			value := this.SegmentManager.GetValue(value)
			
			this.IOControls.OA1.Set(value)
		}
	}
	
	class SegmentControl {
		Segments := []
		Points := []
		
		__New(callback, parent, options := ""){
			this.parent := parent
			this.callback := callback
			Gui, Add, ListView, % "hwndhwnd w130 h75 section " options, Input|Output
			LV_ModifyCol(1, 54)
			LV_ModifyCol(2, 54)
			this.hLV := hwnd
			Gui, Add, Button, hwndhwnd x+5 yp w20 h75, -
			fn := this.DeleteClicked.Bind(this)
			GuiControl, +g, % hwnd, % fn
			Gui, Add, Edit, xs y+5 hwndhwnd w60
			this.hEditInput := hwnd
			Gui, Add, Edit, x+10 yp hwndhwnd w60
			this.hEditOutput := hwnd
			Gui, Add, Button, hwndhwnd x+5 yp w20, +
			fn := this.AddClicked.Bind(this)
			GuiControl, +g, % hwnd, % fn
		}
		
		; Set save to false when loading settings, to avoid triggering save on load
		_AddPoint(i, o){
			if (!this.IsNumeric(i) || !this.IsNumeric(o)){
				return false
			}
			inserted := false
			for index, obj in this.Points {
				if (obj[1] == i)
					return false
				if (obj[1] > i){
					this.Points.Insert(index, [round(i, 2), round(o, 2)])
					inserted := true
					break
				}
			}
			if (!inserted){
				this.Points.push([round(i, 2), round(o, 2)])
			}
			return true
		}
		
		_RemovePoint(index){
			this.Points.RemoveAt(index)
			this.BuildSegments()
			this.SaveSettings()
		}
		
		LoadSettings(str){
			this.Points := []
			chunks := StrSplit(str, "|")
			for i, pt in chunks {
				p := StrSplit(pt, ",")
				res := this._AddPoint(p[1], p[2], false)
			}
			this.BuildSegments()
		}
		
		SaveSettings(){
			str := ""
			for i, chunk in this.Points {
				if (i > 1){
					str .= "|"
				}
				str .= chunk[1] "," chunk[2]
			}
			this.callback.Call(str)
		}
		
		SetInputBox(value){
			GuiControl, , % this.hEditInput, % round(value, 2)
		}
		
		BuildSegments(){
			gui, % this.parent.hwnd ":default"
			Gui, ListView, % this.hLV
			LV_Delete()
			for i, p in this.Points {
				LV_Add(, p[1], p[2])
			}
			pts := this.Points.clone()
			;~ pts.Insert(1, [0,0])
			pts.Push([100,100])
			;~ p0 := pts.removeat(1)
			p0 := [0,0]
			this.Segments := []
			for i, p1 in pts {
				this.Segments.push( {k : (p1.2-p0.2) / (p1.1-p0.1) , m : ( p1.1*p0.2 - p0.1*p1.2 ) / (p1.1-p0.1), end : p1.1 } ), p0 := p1
			}
		}
		
		AddClicked(){
			GuiControlGet, i, , % this.hEditInput
			GuiControlGet, o, , % this.hEditOutput
			if (!this._AddPoint(i, o)){
				SoundBeep, 200, 500
				return
			}
			this.BuildSegments()
			this.SaveSettings()
		}
		
		DeleteClicked(){
			Gui, ListView, % this.hLV
			row := LV_GetNext()
			this._RemovePoint(row)
		}
		
		IsNumeric(str){
			if str is number
				return true
			return false
		}
		
		GetValue(x){
			for i, seg in this.Segments
				if (x <= seg.end)
					return x*seg.k+seg.m
		}
	}
	
}
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

15 Jan 2018, 16:02

About the only thing that seems wrong is the tab order. If in the "Input" editbox and you hit Tab, it selects the add plugin button or something? I am not sure I know how to make it go to the "Output" editbox
Oliver
Posts: 27
Joined: 11 Jan 2018, 10:50

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

16 Jan 2018, 04:17

So basically if I'd set multiple breakpoints I would get a linear line from [0,0] to the first breakpoint [X,Y], a new line from the first to the second [X,Y], and so on until [100,100]?
Oliver
Posts: 27
Joined: 11 Jan 2018, 10:50

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

16 Jan 2018, 05:39

Sweet! Thumbs up! I think this went from a user request to a stable release-ready version in less than a week.

When will you include it in the release version?

BTW, another added value of the "Copy current position" function is that it removes the need for using tools such as DIView to determine the exact percentage of your physical throttle's detent position.
Oliver
Posts: 27
Joined: 11 Jan 2018, 10:50

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

16 Jan 2018, 16:18

Alrighty but you do realize that might take a while since it seems I'm the only using it and the only one you've presented it to by means of this thread? ;)
pastor_jim

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

16 Jan 2018, 21:39

I am trying to use UCR with my old Thrustmaster FCS/WCS/Elite rudder pedals. I think I have everything configured properly, but when I try to use the GameBind feature, I get an error code. Clicking the button on the throttle that activates Gamebind is okay, but as soon as I click anything else, I get two error boxes. I'm not an expert on this stuff, but I like UCR and I'd like to use it, especially since it should get me around the problem of not being able to hide my physical controller. I'm trying to figure out how to attach a picture of the error box.... Is there an easy way to do that? It begins:

Error in #include file
'D:\Users\Jim\Desktop\UCR\Classes\GuiControls\IOClasses\AHK.ahk":
Parameter # 1 s invalid

Line#
090: (
091: OutputDebug, "UCR|AHK_KBM_Input Freed"

There's a lot more, but I am hoping that will help.
daveamerica
Posts: 8
Joined: 21 Nov 2017, 15:55

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

17 Jan 2018, 01:03

Hi again @evilC - app still looking great!

Just wondering, with the update, if there is anyway to control my throttle on my joystick so that I can slowly roll on and off. I’m playing IL2 and it has the ability to set buttons (+/-) or an axis. I’d love to combine the hat up/down into an axis and use that. At first I had the settings set to full on or full off, but then went with 10% as the increment. This works ok but I still have to hit the hat up or down to jump to that throttle speed. Eg if I’m full throttle and want 70% I have to hit hat down 3 times.

Basically, is there anyway I can set up a gradual throttle up and down that’ll stick went rolling off?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

17 Jan 2018, 02:20

@ evilC, the listView is now fine :thumbup:
Smoothchat

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

17 Jan 2018, 05:14

Thankyou for this very useful tool.

I was able to achieve what I have been looking for for years, a means to almost double my controller buttons by assigning a "shift" button so I can have 2 game functions per button as well as effectively adding extra buttons to my joystick.

I have created a plugin that caters for up to 16 input buttons with the ability to nominate one as the "shift" thereby giving you up to 30 functions using vJoy and it's virtual buttons.

You can also load the plugin more than once to assign an additional shift key. You should only assign "non-shift" buttons in the first plugin tho, although it's possible to set up multiple buttons on a single button press (by using multiple copies of the same plugin) if that suits your needs.

It depends on how many buttons you have to start with of course as you are assigning 2 functions to each as well as quarantining a "shift" button.

I am happy to post the code. Where is the best place to do so? I have called the plugin ButtonsToButtons.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

17 Jan 2018, 07:00

I am happy to post the code. Where is the best place to do so? I have called the plugin ButtonsToButtons.
I'd recommend at the same section within a new/separate thread. If you want to link to a specific topic within this/a foreign thread/post, you can right-click on the date-stamp of the post and copy its link for reference. Thx for sharing and happy scripting :thumbup:
Oliver
Posts: 27
Joined: 11 Jan 2018, 10:50

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

18 Jan 2018, 15:49

@evilC I wanna share it with some flying buddies for them to try/test it, would you rather put it in some experimental build and distribute that on your site or do you want me to redirect my buddies to your latest official build and have me share the plug-in script on our own site?
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

18 Jan 2018, 20:39

Post the code
In general, I advise that people distribute specialized plugins themselves and people just keep them in their User plugins folder - all shipped versions of UCR have an empty user folder, so I can release new stuff and not impact user's own custom plugins.
However, if the plugin is of a generic nature, it may be worth chucking it into the main UCR distro.

FYI, you can do shift states by using profile switching, but doing it all in one plugin is a perfectly valid approach too.
I would normally recommend that you use a name a little less generic than "ButtonToButtons" - just bear in mind if ever a core plugin got released with the same name, it may break :P

Whilst I always welcome people writing plugins for UCR, as you may have noticed I have ceased developing the core functionality of this version, we are developing basically the same app in C# as it is much faster and more suited to an app of this complexity.
If you know any C#, or are interested in learning, you are welcome to join us, but if not, just to warn you that I will not be supporting this version long-term, so I would not advise sinking too much time into learning how to code for it ;)
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

19 Jan 2018, 17:11

Hi Mr. evilC
Thank you very very much for this great work,
Can you explain the video to some examples of

Thanks
smootchat
Posts: 9
Joined: 17 Jan 2018, 00:57

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

20 Jan 2018, 06:18

For those that may be interested, I have posted the ButtonsToButtons code here https://autohotkey.com/boards/viewtopic ... 37#p195237. There is a more elegant version towards the end of the thread.
smootchat
Posts: 9
Joined: 17 Jan 2018, 00:57

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

20 Jan 2018, 18:20

I need some advice from an AHK/UCR GURU.

I would like to be able to load ButtonsToButtons twice so I can have 2 shift keys for the same function key, but to do so, each plugin has to cooperate with the other.

I am able to share a common variable between them (ButtonsToButtons.GlobalShiftFlag), but I'd also like one plugin to call or trigger/message a function within the "other" plugin. Perhaps setting up a listener and sending a message to it.

I'm sorry if this is a newbie question. I am new to AHK

Any advice would be appreciated.

Edit: I got it going refering to the class objects and methods, but could only get it to work as planned, if I created 2 separate scripts with unique classes and function names. I couldn't get it to work as p;lanned with 2 copies of the same script loaded.
Last edited by smootchat on 22 Jan 2018, 04:21, edited 3 times in total.
smootchat
Posts: 9
Joined: 17 Jan 2018, 00:57

Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017

22 Jan 2018, 04:12

Hello evilC,

I am very happy with the results I am getting from ButtonsToButtons. I can use a single loaded plugin and double the number of joystick buttons available to assign in my flightsim.

I wrote the code in order to be able to load more than one copy and assign each it's own shift button so I could triple the number of buttons etc.

My goal is to be able to assign multiple shift buttons to a given output button

This would mean that plugin 1 would have button "A" as the shift, and button "C" as an input. Plugin 2 would have button "B" as shift, but still have button "C" as an input. Unfortunately, button "C" only triggers in one plugin, UNLESS it is a hat switch !

A hatswitch defined as an input in every plugin happily triggers in every plugin.

Do you know why there would be a difference between buttons and the hat switch?

I need to understand what it is about the hatswitch that allows it work in both plugins, and try to apply that to the Joystick buttons.

Any advice would be most welcome. Thanks.

Here, I have pressed both button 3 and the Hat "UP"

Image
Attachments
Capture.jpg
Capture.jpg (128.76 KiB) Viewed 3141 times

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 40 guests