Update: UCR plugin:shift button and extra joystick buttons

Post gaming related scripts
smootchat
Posts: 9
Joined: 17 Jan 2018, 00:57

Update: UCR plugin:shift button and extra joystick buttons

17 Jan 2018, 22:40

Updated: Scroll down to see updated versions.

I call this plugin, ButtonsToButtons

This will allow assigning one button or key as a "shift" and reassigning up to 16 shifted and non-shifted buttons to the vJoy virtual joystick (which has over 64 buttons).

You can load more than one plugin at once and assign a different shift button, but there is some overlap and it needs to be experimented to get the right outcome. Hat buttons seem happy to duplicate, others not.

You can get combinations happening if you load the same plugin twice and assign either the same keys or others. These side effects may or may not be desirable.

It's possible in some cases to assign two output against one input if you have more than one plugin loaded.

The "Ignore if other proc shifted" checkbox is to help overcome the situation where you have 2 plugins loaded, and the first plugin sees your shift key, but the second only sees your output key. You might have 2 virtual buttons activate at one time which may not be desirable. It's kinda hard to explain. Only way to understand is to just experiment.

I used the original ButtonToButton plugin as a template. Thanks go to the original author.

Code: Select all

/*
A sample plugin to map a digital input to a digital output
When UCR is finished, valid inputs will be:
Keyboard*, Mouse Buttons/Wheel*, Joystick Buttons, Joystick Hat directions
Modes supported (Key / Mouse only): Block, Wild, Repeat Supression
Valid outputs will be:
Keyboard, Mouse Buttons/Wheel, Virtual Joystick Buttons / Hat directions
*/

Global GlobalShiftingFlag = 0 ; Lets us know if another instance is currently in shift mode.


; All plugins must derive from the _Plugin class
class ButtonsToButtons extends _UCR.Classes.Plugin {
	Type := "Remapper (Buttons To Buttons)"
	Description := "Remaps 16 buttons as well as a shift button to assign another 16 virtual buttons"

	LocalShiftingFlag := 0     ; Use this and the GlobalShiftingFlag to know whether this or other instances 
	; are in shift mode and avoid holding down 2 buttons at once if possible.
	
	
	; The Init() method of a plugin is called when one is added. Use it to create your Gui etc

	Init(){
		
		
		; Create the GUI
		iow := 125
		
		
		
		Gui, Add, GroupBox, Center xm ym w165 h60 section, Shift Button
		this.AddControl("InputButton", "IB1", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+15")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB1, "x+5 yp+5")
		
		
		
		Gui, Add, GroupBox, Center x175 ym w165 h730	section, Input Button        .
		this.AddControl("InputButton", "IB2", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+15")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB2, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB3", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB3, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB4", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB4, "x+5 yp+5")		
		
		this.AddControl("InputButton", "IB5", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB5, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB6", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB6, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB7", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB7, "x+5 yp+5")

		this.AddControl("InputButton", "IB8", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB8, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB9", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB9, "x+5 yp+5")

		this.AddControl("InputButton", "IB10", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB10, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB11", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB11, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB12", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB12, "x+5 yp+5")		
		
		this.AddControl("InputButton", "IB13", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB13, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB14", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB14, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB15", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB15, "x+5 yp+5")

		this.AddControl("InputButton", "IB16", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB16, "x+5 yp+5")
		
		this.AddControl("InputButton", "IB17", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB17, "x+5 yp+5")
	

	
		Gui, Add, GroupBox, Center x340 ym w170 h730 section, Non-Shifted Output Button            .
		this.AddControl("OutputButton", "OB1", 0, "xs+5 yp+15")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB1, "x+5 yp+5")

		this.AddControl("OutputButton", "OB3", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB3, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB5", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB5, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB7", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB7, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB9", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB9, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB11", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB11, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB13", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB13, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB15", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB15, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB17", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB17, "x+5 yp+5")

		this.AddControl("OutputButton", "OB19", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB19, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB21", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB21, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB23", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB23, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB25", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB25, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB27", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB27, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB29", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB29, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB31", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB31, "x+5 yp+5")
		
			
		
		Gui, Add, GroupBox, Center x510 ym w170 h730 section, Shifted Output	Button           .
		this.AddControl("OutputButton", "OB2", 0, "xs+5 ys+15")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB2, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB4", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB4, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB6", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB6, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB8", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB8, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB10", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB10, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB12", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB12, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB14", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB14, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB16", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB16, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB18", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB18, "x+5 yp+5")
		
		this.AddControl("OutputButton", "OB20", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB20, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB22", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB22, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB24", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB24, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB26", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB26, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB28", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB28, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB30", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB30, "x+5 yp+5")
				
		this.AddControl("OutputButton", "OB32", 0, "xs+5 yp+40")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.OB32, "x+5 yp+5")
		
	   ;If another copy of this plugin is loaded, don't produce non-shifted button if other shift key is pressed.
   	Gui, Add, GroupBox, Center xm ym+60 w165 h60 section, Settings
		this.AddControl("Checkbox", "Toggle", 0, "xs+5 yp+30", "Ignore If Other Proc Shifted")				

; Clear the controls , otherwise they sometimes initialize with a '-1'
		
		this.IOControls.IB1.Set(0)
		this.IOControls.IB2.Set(0)
		this.IOControls.IB3.Set(0)
		this.IOControls.IB4.Set(0)
		this.IOControls.IB5.Set(0)
		this.IOControls.IB6.Set(0)
		this.IOControls.IB7.Set(0)
		this.IOControls.IB8.Set(0)
		this.IOControls.IB9.Set(0)
		this.IOControls.IB10.Set(0)
		this.IOControls.IB11.Set(0)
		this.IOControls.IB12.Set(0)
		this.IOControls.IB13.Set(0)
		this.IOControls.IB14.Set(0)
		this.IOControls.IB15.Set(0)
		this.IOControls.IB16.Set(0)
		this.IOControls.IB17.Set(0)
		
	}
	
	; The main code is here. Called when a key or button changes state (pressed or released)
	MyHkChangedState(e){
		;OutputDebug, % "UCR| Plugin" this.Name " changed state to: " (e ? "Down" : "Up")		
		;OutputDebug, % "GlobalShiftingFlag = " GlobalShiftingFlag
		;OutputDebug, % "LocalShiftingFlag = " this.localShiftingFlag
				
		
		if(this.IOControls.IB1.Get()){
				this.ClearRealOutputs()
				this.UpdateVirtualOutputs()
				GlobalShiftingFlag = 1
				this.LocalShiftingFlag := 1
		}else {					
					if(GlobalShiftingFlag == 1){
						this.ClearRealOutputs()
					}
					
				if(this.GuiControls.Toggle.Get()){ ; If checked and another process shift key is pressed, don't produce non-shifted button
				
					if(GlobalShiftingFlag == 0 || this.LocalShiftingFlag == 1) { ;If only my shift key is pressed
						this.ClearVirtualOutputs()
						this.UpdateRealOutputs()
						GlobalShiftingFlag = 0
						this.LocalShiftingFlag := 0
				
					}
				}else{
						this.ClearVirtualOutputs()
						this.UpdateRealOutputs()
						GlobalShiftingFlag = 0
						this.LocalShiftingFlag := 0
				}
		}
	}
	
	ClearVirtualOutputs()
	{
			this.IOControls.OB2.Set(0)
			this.IOControls.OB4.Set(0)
			this.IOControls.OB6.Set(0)
			this.IOControls.OB8.Set(0)
			this.IOControls.OB10.Set(0)
			this.IOControls.OB12.Set(0)
			this.IOControls.OB14.Set(0)
			this.IOControls.OB16.Set(0)
			this.IOControls.OB18.Set(0)
			this.IOControls.OB20.Set(0)
			this.IOControls.OB22.Set(0)
			this.IOControls.OB24.Set(0)
			this.IOControls.OB26.Set(0)
			this.IOControls.OB28.Set(0)
			this.IOControls.OB30.Set(0)
			this.IOControls.OB32.Set(0)
	}

	

	ClearRealOutputs()
	{
			this.IOControls.OB1.Set(0)
			this.IOControls.OB3.Set(0)
			this.IOControls.OB5.Set(0)
			this.IOControls.OB7.Set(0)
			this.IOControls.OB9.Set(0)
			this.IOControls.OB11.Set(0)
			this.IOControls.OB13.Set(0)
			this.IOControls.OB15.Set(0)
			this.IOControls.OB17.Set(0)
			this.IOControls.OB19.Set(0)
			this.IOControls.OB21.Set(0)
			this.IOControls.OB23.Set(0)
			this.IOControls.OB25.Set(0)
			this.IOControls.OB27.Set(0)
			this.IOControls.OB29.Set(0)
			this.IOControls.OB31.Set(0)
	}

	UpdateVirtualOutputs()
	{
			this.IOControls.OB2.Set(this.IOControls.IB2.Get())
			this.IOControls.OB4.Set(this.IOControls.IB3.Get())
			this.IOControls.OB6.Set(this.IOControls.IB4.Get())
			this.IOControls.OB8.Set(this.IOControls.IB5.Get())
			this.IOControls.OB10.Set(this.IOControls.IB6.Get())
			this.IOControls.OB12.Set(this.IOControls.IB7.Get())
			this.IOControls.OB14.Set(this.IOControls.IB8.Get())
			this.IOControls.OB16.Set(this.IOControls.IB9.Get())
			this.IOControls.OB18.Set(this.IOControls.IB10.Get())
			this.IOControls.OB20.Set(this.IOControls.IB11.Get())
			this.IOControls.OB22.Set(this.IOControls.IB12.Get())
			this.IOControls.OB24.Set(this.IOControls.IB13.Get())
			this.IOControls.OB26.Set(this.IOControls.IB14.Get())
			this.IOControls.OB28.Set(this.IOControls.IB15.Get())
			this.IOControls.OB30.Set(this.IOControls.IB16.Get())
			this.IOControls.OB32.Set(this.IOControls.IB17.Get())
	}
	
	UpdateRealOutputs()
	{
			this.IOControls.OB1.Set(this.IOControls.IB2.Get())
			this.IOControls.OB3.Set(this.IOControls.IB3.Get())
			this.IOControls.OB5.Set(this.IOControls.IB4.Get())
			this.IOControls.OB7.Set(this.IOControls.IB5.Get())
			this.IOControls.OB9.Set(this.IOControls.IB6.Get())
			this.IOControls.OB11.Set(this.IOControls.IB7.Get())
			this.IOControls.OB13.Set(this.IOControls.IB8.Get())
			this.IOControls.OB15.Set(this.IOControls.IB9.Get())
			this.IOControls.OB17.Set(this.IOControls.IB10.Get())
			this.IOControls.OB19.Set(this.IOControls.IB11.Get())
			this.IOControls.OB21.Set(this.IOControls.IB12.Get())
			this.IOControls.OB23.Set(this.IOControls.IB13.Get())
			this.IOControls.OB25.Set(this.IOControls.IB14.Get())
			this.IOControls.OB27.Set(this.IOControls.IB15.Get())
			this.IOControls.OB29.Set(this.IOControls.IB16.Get())
			this.IOControls.OB31.Set(this.IOControls.IB17.Get())
	}
	
}

Image

The plugin is named .. ButtonsToButtons.ahk

The above goes in the UCR/plugins/user/folder

Main programs are here ...

https://autohotkey.com/boards/viewtopic ... cr+plugins

http://vjoystick.sourceforge.net/site/i ... l/download

You set up all the virtual buttons and then assign in your game. You can merge several joysticks into one, have a mixture of your physical, virtual and shifted virtual buttons depending on what you assign in UCR and your game.
Last edited by smootchat on 21 Jan 2018, 21:37, edited 3 times in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: UCR plugin:shift button and extra joystick buttons

18 Jan 2018, 05:57

Hello, thanks for sharing :wave:.

Minor comments, you can use a static variable instead of the global, eg,

Code: Select all

class ButtonsToButtons extends _UCR.Classes.Plugin {
	static GlobalShiftingFlag := 0 ; Lets us know if another instance is currently in shift mode.
	; ...
	MyHkChangedState() {
		; something
		ButtonsToButtons.GlobalShiftingFlag  := ...
		; something
	}
}
Avoing globals is an unspoken convention for UCR plugins, I believe, but as I said, it it minor. For future projects, keep in mind that loop can reduce your typing efforts substantially, eg,

Code: Select all

this.IOControls.IB1.Set(0)
; ...
this.IOControls.IB17.Set(0)
can be replaced with

Code: Select all

loop 17
	this.IOControls["IB" A_Index].Set(0)
I will link to this in my UCR plugin thread (and now I've link to mine ;) ), to make it easier for people to find custom plugins.

Cheers.
smootchat
Posts: 9
Joined: 17 Jan 2018, 00:57

Re: UCR plugin:shift button and extra joystick buttons

18 Jan 2018, 08:42

Yeah thanks for the advice. I knew it wasn't elegant, but I wanted to share it anyway.

I'll have a go at cleaning it up.
smootchat
Posts: 9
Joined: 17 Jan 2018, 00:57

Re: UCR plugin:shift button and extra joystick buttons

18 Jan 2018, 22:53

Here is a cleaner version with a few touchups to the logic as well. Updated to V1.02

Code: Select all

;Global variables
ButtonsToButtons.GlobalShiftingFlag  := 0 ; available to all instances, lets us know if another instance is currently in shift mode.
	
	
class ButtonsToButtons extends _UCR.Classes.Plugin {
	Type := "Remapper (Buttons To Buttons)"
	Description := "Remaps 16 buttons as well as a shift button to assign another 16 virtual buttons"

	LocalShiftingFlag := 0     ; Use this and the GlobalShiftingFlag to know whether this or other instances 
										; are in shift mode and avoid holding down 2 buttons at once if possible.
	


	Init(){  ; Create the GUI
			
		;Create Primary shift button
		Gui, Add, GroupBox, Center xm ym w165 h60 section, Shift Button
		this.AddControl("InputButton", "IB1", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+15")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB1, "x+5 yp+5")
				
		;Each group of buttons requires its own loop because they position relative to each other.	
		Loop 16 {  ; Create Input Buttons
			if(A_Index==1) {
				Gui, Add, GroupBox, Center x175 ym w165 h730	section, Input Button        .
				this.AddControl("InputButton", "IB" + A_Index+1, 0, this.MyHkChangedState.Bind(this), "xs+5 yp+15")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["IB" A_Index+1], "x+5 yp+5")			
			}else{
				this.AddControl("InputButton", "IB" + A_Index+1, 0, this.MyHkChangedState.Bind(this), "xs+5 yp+40")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["IB" A_Index+1], "x+5 yp+5")
			}	
		}
	

		Loop 16 {   ; Create Non-Shifted Output Buttons
			if(A_Index==1) {
				Gui, Add, GroupBox, Center x340 ym w170 h730 section, Non-Shifted Output Button            .
				this.AddControl("OutputButton", "OB" + A_Index, 0, "xs+5 yp+15")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index], "x+5 yp+5")
			}else{
				this.AddControl("OutputButton", "OB" + A_Index, 0, "xs+5 yp+40")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index], "x+5 yp+5")
			}
		}
			
		Loop 16 {   ; Create Shifted Output Buttons
			if(A_Index==1) {		
				Gui, Add, GroupBox, Center x510 ym w170 h730 section, Shifted Output	Button           .
				this.AddControl("OutputButton", "OB" + A_Index+16, 0, "xs+5 ys+15")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index+16], "x+5 yp+5")
			}else{
				this.AddControl("OutputButton","OB" + A_Index+16, 0, "xs+5 yp+40")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index+16], "x+5 yp+5")
			}
		}
				
		;Checkbox. If another copy of this plugin is loaded, disable non-shifted button if other plugin shift key is pressed.
		Gui, Add, GroupBox, Center xm ym+60 w165 h65 section, Settings
		this.AddControl("Checkbox", "Toggle", 0, "xs+5 yp+30", "Disable Non-Shift output if")				
		Gui, Add, Text, y+1, % "      another plugin is Shifted"
		
		;Clear the controls , otherwise they sometimes initialize with a '-1'	
		loop 17 {
		this.IOControls["IB" A_Index].Set(0)
		}
	
	}
	
	; The main code is here. Called when a key or button changes state (pressed or released)
	MyHkChangedState(e){
		;OutputDebug, % "UCR| Plugin" this.Name " changed state to: " (e ? "Down" : "Up")		
		
		if(this.IOControls.IB1.Get()){ ; Shift key is down so produce Shifted Button output
			this.ClearNonShiftedOutputs()
			this.UpdateShiftedOutputs()
			ButtonsToButtons.GlobalShiftingFlag  := 1
			this.LocalShiftingFlag := 1
		}else {	
		
			;If "Disable Non-Shifted" is checked, apply rule to non-shifted output		
			if(this.GuiControls.Toggle.Get()){ 
														  

				;If no other shift, or my shift key is pressed
				if(ButtonsToButtons.GlobalShiftingFlag == 0 || this.LocalShiftingFlag == 1) { 
					this.ClearShiftedOutputs()
					this.UpdateNonShiftedOutputs()
					ButtonsToButtons.GlobalShiftingFlag  := 0
					this.LocalShiftingFlag := 0			
				}else
				{
					this.ClearShiftedOutputs()
					this.ClearNonShiftedOutputs()
					this.LocalShiftingFlag := 0					
				}
								
			}else{
					;If "Disable Non-Shifted" is not checked, just output non-shifted 
						this.ClearShiftedOutputs()
						this.UpdateNonShiftedOutputs()
						ButtonsToButtons.GlobalShiftingFlag  := 0
						this.LocalShiftingFlag := 0
			}
		}
	}
	
	ClearNonShiftedOutputs(){
			Loop 16
			this.IOControls["OB" A_Index].Set(0)
	}

	UpdateNonShiftedOutputs(){
			Loop 16 
			this.IOControls["OB" A_Index].Set(this.IOControls["IB" A_Index+1].Get())
	}

	ClearShiftedOutputs(){
			Loop 16
			this.IOControls["OB" A_Index+16].Set(0)
	}

	UpdateShiftedOutputs(){
			Loop 16 
			this.IOControls["OB" A_Index+16].Set(this.IOControls["IB" A_Index+1].Get())
	}
	
}

Old Version Screenshot (New version looks the same except for the checkbox text)
Image
Attachments
ButtonsToButtons v1.02.zip
(1.43 KiB) Downloaded 127 times
Capture.jpg
Capture.jpg (192.3 KiB) Viewed 2524 times
smootchat
Posts: 9
Joined: 17 Jan 2018, 00:57

Re: UCR plugin:shift button and extra joystick buttons

21 Jan 2018, 21:27

Update 2.2

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

eg

Up_Hatswitch looks up (as normal)
Shift + Up_Hatswitch Raises Flaps
Shift2 + Up_Hatswitch Raises Gear
Shift3 + Up_Hatswitch Starts Engine

Thereby quadrupling the number of available functions per button.

(Note: You can double your joystick buttons with one plugin loaded. Multiple plugins and multiple shifts only seem to work with the hat switch at this point in time)

eg: Button 1 as shift button, HatSwitch "UP" as "input" button.

The hatswitch can be an input in several loaded ButtonsToButtons plugins, but a normal button will only trigger in one of the plugins.

Here is a more multi process aware version to help prevent multiple plugin situations where one plugin output conflicts with another plugins output.

The multi process aware versions require a unique plugin file for each shift key. There are 4 variables/function names within each that are unique, allowing them to "play nicely" together.

There is also a less "smart" version.
This is single file which you can load as many times as you like, however it is less smart or "aware" of other instances of itself and you may get output duplication or odd things happening. But it is mostly well behaved, especially if you use the UCR profile switcher to switch between input output sets. In which case you might only use theButtonsToButtons plugin to redirect several buttons via a single plugin.

Here is the multi process version for your perusal.

The Inter Process communication is simply done by calling functions within each plugin's class. A global array holds the object references required.

Much of the shifting function is made redundant by the UCR Profile switcher plugin, but someone might find parts of this to be useful.

I apologize to the purists as I have broken a few rules regarding global variables and class method and library etiquette in order to get this to work.

The full set of required files and instructions is included in the attached zip.

Saitek Yoke Users: Remember to delete or rename the SaiD0BAC.pr0 file in the system32 directory to get access to the mode switch.

Code: Select all

;Global variables
Global GlobalShiftingFlag  = 0 ; available to all instances, lets us know if another instance is currently in shift mode.
Global GlobalNonShiftingFlag  = 0 ; available to all instances, lets us know if another instance is currently in nonshift mode.	
Global Process := []

; ########    The functions and variables between the #'s must be unique to each loaded plugin NumProcesses must equal the number of loaded plugins
Global NumProcesses := 3 																	;  How many copies of this plugin.

class ButtonsToButtons1 extends _UCR.Classes.Plugin {								; Change for each instance
	Type := "Remapper (Buttons To Buttons1)"											; Change for each instance
	MyProcessID := 1																			; Change for each instance
; ########	
	Description := "Remaps buttons as well as a shift button to create another set of virtual buttons"
	LocalShiftingFlag := 0     ; Use this and the GlobalShiftingFlag to know whether this or other instances 
									; are in shift mode and avoid holding down 2 buttons at once if possible.
	NumberOfButtons := 20
	Init(){  ; Create the GUI
			
		;Create Primary shift button
		Gui, Add, GroupBox, Center xm ym w165 h60 section, Shift Button
		this.AddControl("InputButton", "IB1", 0, this.MyHkChangedState.Bind(this), "xs+5 yp+15")
		this.AddControl("ButtonPreview", "", 0, this.IOControls.IB1, "x+5 yp+5")
				
		;Each group of buttons requires its own loop because they position relative to each other.	
		Loop % this.NumberOfButtons {  ; Create Input Buttons
			if(A_Index==1) {
				Gui, Add, GroupBox, Center x175 ym w165 h760	section, Input Button        .
				this.AddControl("InputButton", "IB" + A_Index+1, 0, this.MyHkChangedState.Bind(this), "xs+5 yp+15")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["IB" A_Index+1], "x+5 yp+5")			
			}else{
				this.AddControl("InputButton", "IB" + A_Index+1, 0, this.MyHkChangedState.Bind(this), "xs+5 yp+32")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["IB" A_Index+1], "x+5 yp+5")
			}	
		}
	

		Loop % this.NumberOfButtons {   ; Create Non-Shifted Output Buttons
			if(A_Index==1) {
				Gui, Add, GroupBox, Center x340 ym w170 h760 section, Non-Shifted Output Button            .
				this.AddControl("OutputButton", "OB" + A_Index, 0, "xs+5 yp+15")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index], "x+5 yp+5")
			}else{
				this.AddControl("OutputButton", "OB" + A_Index, 0, "xs+5 yp+32")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index], "x+5 yp+5")
			}
		}
			
		Loop % this.NumberOfButtons {   ; Create Shifted Output Buttons
			if(A_Index==1) {		
				Gui, Add, GroupBox, Center x510 ym w170 h760 section, Shifted Output	Button           .
				this.AddControl("OutputButton", "OB" + A_Index+this.NumberOfButtons, 0, "xs+5 ys+15")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index+this.NumberOfButtons], "x+5 yp+5")
			}else{
				this.AddControl("OutputButton","OB" + A_Index+this.NumberOfButtons, 0, "xs+5 yp+32")
				this.AddControl("ButtonPreview", "", 0, this.IOControls["OB" A_Index+this.NumberOfButtons], "x+5 yp+5")
			}
		}
				
		;Checkbox. If another copy of this plugin is loaded, disable non-shifted button if other plugin shift key is pressed.
		Gui, Add, GroupBox, Center xm ym+60 w165 h110 section, Settings
		this.AddControl("Checkbox", "EnableNonShift", 0, "xs+5 yp+30", " Enable Non-Shift output if")				
		Gui, Add, Text, y+1, % "       another plugin is Shifted"

		this.AddControl("Checkbox", "EnableFlip", 0, "xs+5 yp+30", " Re-enable Non Shifted")	
		Gui, Add, Text, y+1, % "       after shift release"
		
		;Clear the controls , otherwise they sometimes initialize with a '-1'	
		loop % this.NumberOfButtons + 1 {
		this.IOControls["IB" A_Index].Set(0)
		}
	
	}
	
	; The main code is here. Called when a key or button changes state (pressed or released)
	MyHkChangedState(e){
		;OutputDebug, % "UCR| Plugin" this.Name " changed state to: " (e ? "Down" : "Up")		
		Process[this.MyProcessID] := this ; Store this object ref globally so other processes can see it
		
		if(this.IOControls.IB1.Get()){ ; Shift key is down so produce Shifted Button output
		
			if(GlobalNonShiftingFlag == 1){
				; Tell other process to clear it's nonshifted buttons if enable non shift is NOT set
					loop % NumProcesses
					if(!Process[A_Index].GuiControls.EnableNonShift.Get() && A_Index != this.MyProcessID)
						Process[A_Index].ClearNonShiftedOutputs()
			}		
		
			this.ClearNonShiftedOutputs()
			this.UpdateShiftedOutputs()
			GlobalShiftingFlag  := 1
			this.LocalShiftingFlag := 1
		}else {	
		
			;If "Enable Non-Shifted" is checked, apply rule to non-shifted output		
			if(!this.GuiControls.EnableNonShift.Get()){ 
														  
				;If no other shift, or my shift key is pressed
				if(GlobalShiftingFlag == 0 || this.LocalShiftingFlag == 1) { 
					this.ClearShiftedOutputs()
					;If "Re-enable Non shifted" is checked, or we are not shifted
					if (this.GuiControls.EnableFlip.Get() || this.LocalShiftingFlag != 1)
						this.UpdateNonShiftedOutputs()
					;If "Re-enable Non shifted"" is checked in other process, update their nonshifted
					loop % NumProcesses {
						if (Process[A_Index].GuiControls.EnableFlip.Get() && A_Index != this.MyProcessID)
							Process[A_Index].UpdateNonShiftedOutputs()	
						}
					GlobalShiftingFlag  := 0
					this.LocalShiftingFlag := 0			
				}else
				{
					; If we got here, it means we have released a non-shifted button
					; Other processes will clean up GlobalShiftingFlag when it's shift key is released
					this.ClearShiftedOutputs()
					this.ClearNonShiftedOutputs()
					this.LocalShiftingFlag := 0					
				}
								
			}else{
					;If "Disable Non-Shifted" is not checked, just output non-shifted 
						this.ClearShiftedOutputs()
						this.UpdateNonShiftedOutputs()
						GlobalShiftingFlag  := 0
						this.LocalShiftingFlag := 0
			}
		}
	}
	
	ClearNonShiftedOutputs(){
			Loop % this.NumberOfButtons
			this.IOControls["OB" A_Index].Set(0)
			GlobalNonShiftingFlag  := 0
	}

	UpdateNonShiftedOutputs(){
			Loop % this.NumberOfButtons {
				if(this.IOControls["IB" A_Index+1].Get()){
					this.IOControls["OB" A_Index].Set(1)
					GlobalNonShiftingFlag  := 1
				}else{
					this.IOControls["OB" A_Index].Set(0)
				}
			}
	}

	ClearShiftedOutputs(){
			Loop % this.NumberOfButtons
			this.IOControls["OB" A_Index+this.NumberOfButtons].Set(0)
	}

	UpdateShiftedOutputs(){
			Loop % this.NumberOfButtons 
			this.IOControls["OB" A_Index+this.NumberOfButtons].Set(this.IOControls["IB" A_Index+1].Get())
	}

}

My setup for the Saitek Yoke + extra Throttle quadrant. I now have 40 functions avialable by doubling the buttons and using the mode switch to toggle between shifted and unshifted mode.
Image
Attachments
ButtonsToButtons v2.3.zip
(10.72 KiB) Downloaded 144 times
Capture.jpg
Capture.jpg (158.47 KiB) Viewed 2524 times

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 33 guests