Got around to using, but actually testing, my previous script in action with game play.
It was again confirmed that I am no "coder", lucky if I can copy and paste with any proficiency it seems.
So I had another look at your (evilC) suggestion for keyevent and changed the "if" statement to a "not equal", and it works (in game) like a charm.
And now I am going to take my slightly older headache in to the bush and see if we cant loose each other. Any bets on which one returns?
The below should now be a complete and working version of Synapse3_Replacement_V1.ahk as it was intended.
Please, anyone, feel free to adapt and change it to your needs.
Code: Select all
;Synapse3_ReplacementV1.ahk
;This is a replacement for Razers Synapse3 beta software and driver for the Tartarus V2.
;Also can replace the original Belkin drivers and software for the Nostromo N50 & N52.
;Successfully tested with a small number of generic half-a-keyboards (gaming keypads).
;With minor adjustments it shouldn't be too hard to make it work with other keypad (half-a-keyboard) devices, even incl full keyboards.
;This version will set each key/button/wheel as a virtual joystick button (28 currently).
;Designed to be used in conjunction with advanced configuration software utilities (Xpadder or Pinnacle Game Profiler, etc).
;Do not use this script if you are using UCR, Universal Control Remapper by evilC.
;Special thanks to evilC for the additional libraries, and the AutoHotkey team and community.
;This script requires AutoHotInterception and CvJoyInterface libraries, and Shaul's vJoy. Follow install instructions at evilCs github.
#SingleInstance force
#Persistent
#HotkeyInterval 2000
#MaxHotkeysPerInterval 200
#MaxThreadsBuffer on
#include <AutoHotInterception>
#include <CvJoyInterface>
SetBatchLines, -1
ListLines, Off
; Create an object from vJoy Interface Class.
global vJoyInterface := new CvJoyInterface()
global myStick := vJoyInterface.Devices[5]
global AHI := new AutoHotInterception()
;Use Monitor.ahk by evilC to determine device VID and PID for below IDs
global keyboardId := AHI.GetKeyboardId(0x1532, 0x022B)
global MouseId := AHI.GetMouseId(0x1532, 0x022B)
global newstate := 16384
;SetTimer, PollWatch, -0 ;not currently required
; Was vJoy installed and the DLL Loaded?
if (!vJoyInterface.vJoyEnabled()){
; Show log of what happened
Msgbox % vJoyInterface.LoadLibraryLog
ExitApp
}
AHI.SubscribeKey(keyboardId, GetKeySC("1"), true, Func("KeyEvent").Bind(1))
AHI.SubscribeKey(keyboardId, GetKeySC("2"), true, Func("KeyEvent").Bind(2))
AHI.SubscribeKey(keyboardId, GetKeySC("3"), true, Func("KeyEvent").Bind(3))
AHI.SubscribeKey(keyboardId, GetKeySC("4"), true, Func("KeyEvent").Bind(4))
AHI.SubscribeKey(keyboardId, GetKeySC("5"), true, Func("KeyEvent").Bind(5))
AHI.SubscribeKey(keyboardId, GetKeySC("Tab"), true, Func("KeyEvent").Bind(6))
AHI.SubscribeKey(keyboardId, GetKeySC("q"), true, Func("KeyEvent").Bind(7))
AHI.SubscribeKey(keyboardId, GetKeySC("w"), true, Func("KeyEvent").Bind(8))
AHI.SubscribeKey(keyboardId, GetKeySC("e"), true, Func("KeyEvent").Bind(9))
AHI.SubscribeKey(keyboardId, GetKeySC("r"), true, Func("KeyEvent").Bind(10))
AHI.SubscribeKey(keyboardId, GetKeySC("CapsLock"), true, Func("KeyEvent").Bind(11))
AHI.SubscribeKey(keyboardId, GetKeySC("a"), true, Func("KeyEvent").Bind(12))
AHI.SubscribeKey(keyboardId, GetKeySC("s"), true, Func("KeyEvent").Bind(13))
AHI.SubscribeKey(keyboardId, GetKeySC("d"), true, Func("KeyEvent").Bind(14))
AHI.SubscribeKey(keyboardId, GetKeySC("f"), true, Func("KeyEvent").Bind(15))
AHI.SubscribeKey(keyboardId, GetKeySC("LShift"), true, Func("KeyEvent").Bind(16))
AHI.SubscribeKey(keyboardId, GetKeySC("z"), true, Func("KeyEvent").Bind(17))
AHI.SubscribeKey(keyboardId, GetKeySC("x"), true, Func("KeyEvent").Bind(18))
AHI.SubscribeKey(keyboardId, GetKeySC("c"), true, Func("KeyEvent").Bind(19))
AHI.SubscribeKey(keyboardId, GetKeySC("Space"), true, Func("KeyEvent").Bind(20))
AHI.SubscribeKey(keyboardId, GetKeySC("LAlt"), true, Func("KeyEvent").Bind(21))
AHI.SubscribeKey(keyboardId, GetKeySC("Left"), true, Func("KeyEvent").Bind(22))
AHI.SubscribeKey(keyboardId, GetKeySC("Right"), true, Func("KeyEvent").Bind(23))
AHI.SubscribeKey(keyboardId, GetKeySC("Up"), true, Func("KeyEvent").Bind(24))
AHI.SubscribeKey(keyboardId, GetKeySC("Down"), true, Func("KeyEvent").Bind(25))
AHI.SubscribeMouseButton(MouseId, GetKeySC("1"), true, Func("MouseEvent").Bind(26))
AHI.SubscribeMouseButton(MouseId, GetKeySC("4"), true, Func("WheelEvent1"))
;AHI.SubscribeMouseButton(MouseId, GetKeySC("4"), true, Func("WheelEvent2"))
;Choose WheelEvent1 for vjoy button press and remark the other.
;Choose WheelEvent2 for vjoy sl0 axis and remark the other.
return
KeyEvent(btn, state){
static btnStates := {}
if (btnStates![btn])
return ; Filter repeats
btnStates[btn] := state
myStick.SetBtn(state, btn)
}
MouseEvent(btn, state){
static btnStates := {}
if (btnStates![btn])
return ; Filter repeats
btnStates[btn] := state
myStick.SetBtn(state, btn)
}
WheelEvent1(state){
if state = 1
myStick.SetBtn(1, 27)
if state = -1
myStick.SetBtn(1, 28)
sleep 50
myStick.SetBtn(0, 27)
myStick.SetBtn(0, 28)
}
WheelEvent2(state){
if newstate > 32767
newstate = 32768
if newstate < 1
newstate = 0
newstate = % newstate + (state*1000)
myStick.SetAxisByIndex(newstate, 7)
}
PollWatch:
Loop ,26 {
myStick.SetBtn(state,A_Index)
}
return
^Esc::
ExitApp
I added TapHoldManager to my little project. It allows for 32 joystick buttons and the slider axis, with the top row of five keys used for single and double-tap, the "W" key is also single and double-tap, the wheel using the slider axis but configured more like a button, and the D-pad c/w its two neighboring buttons set as standard joystick buttons.
I was initially overthinking the use of TapHoldManager, AutoHotInterception and CvJoyInterface, making it seem harder than it should've been.
I know my script could be written more elegantly but my skills don't extend that far. If anyone get the itch to tidy or improve this script, feel free.
The below should now be a complete and working version of Synapse3_Replacement_V2.ahk with tap-hold support.
A very quick double-tap and hold is required for the extra functionality.
Code: Select all
;Synapse3_ReplacementV2.ahk
;This is a replacement for Razers Synapse3 beta software and driver for the Tartarus V2.
;Also can replace the original Belkin drivers and software for the Nostromo N50 & N52.
;Successfully tested with a small number of generic half-a-keyboards (gaming keypads).
;With minor adjustments it shouldn't be too hard to make it work with other keypad (half-a-keyboard) devices, even incl full keyboards.
;This version will set each key/button/wheel as a virtual joystick button (28 currently).
;Designed to be used in conjunction with advanced configuration software utilities (Xpadder or Pinnacle Game Profiler, etc).
;Do not use this script if you are using UCR, Universal Control Remapper by evilC.
;Special thanks to evilC for the additional libraries, and the AutoHotkey team and community.
;This script requires TapHoldManager, AutoHotInterception and CvJoyInterface libraries, and Shaul's vJoy. Follow install instructions at evilCs github.
#SingleInstance force
#Persistent
#HotkeyInterval 2000
#MaxHotkeysPerInterval 200
#MaxThreadsBuffer on
#include <AutoHotInterception>
#include <CvJoyInterface>
#include <InterceptionTapHold>
SetBatchLines, -1
ListLines, Off
;Your devices VID and PID. For safe keeping, has no impact on the script
;global vpids := 0x1532, 0x022B ;Tartarus V2
;global vpids := 0x050D, 0x0815 ;Nostromo N52
; Create an object from vJoy Interface Class.
global vJoyInterface := new CvJoyInterface()
global myStick := vJoyInterface.Devices[5]
global AHI := new AutoHotInterception()
;Use Monitor.ahk by evilC to determine device VID and PID for below IDs
global keyboardId := AHI.GetKeyboardId(0x1532, 0x022B)
global MouseId := AHI.GetMouseId(0x1532, 0x022B)
global kb1 := new InterceptionTapHold(0x1532, 0x022B)
global newstate := 16384
; Was vJoy installed and the DLL Loaded?
if (!vJoyInterface.vJoyEnabled()){
; Show log of what happened
Msgbox % vJoyInterface.LoadLibraryLog
ExitApp
}
kb1.Add("1", Func("Kb1Func1"),300,100,2) ; tapTime, holdTime, maxTaps, prefixes
kb1.Add("2", Func("Kb1Func2"),300,100,2) ; tapTime, holdTime, maxTaps, prefixes
kb1.Add("3", Func("Kb1Func3"),300,100,2) ; tapTime, holdTime, maxTaps, prefixes
kb1.Add("4", Func("Kb1Func4"),300,100,2) ; tapTime, holdTime, maxTaps, prefixes
kb1.Add("5", Func("Kb1Func5"),300,100,2) ; tapTime, holdTime, maxTaps, prefixes
;AHI.SubscribeKey(keyboardId, GetKeySC("1"), true, Func("KeyEvent").Bind(1))
;AHI.SubscribeKey(keyboardId, GetKeySC("2"), true, Func("KeyEvent").Bind(2))
;AHI.SubscribeKey(keyboardId, GetKeySC("3"), true, Func("KeyEvent").Bind(3))
;AHI.SubscribeKey(keyboardId, GetKeySC("4"), true, Func("KeyEvent").Bind(4))
;AHI.SubscribeKey(keyboardId, GetKeySC("5"), true, Func("KeyEvent").Bind(5))
AHI.SubscribeKey(keyboardId, GetKeySC("Tab"), true, Func("KeyEvent").Bind(6))
AHI.SubscribeKey(keyboardId, GetKeySC("q"), true, Func("KeyEvent").Bind(7))
kb1.Add("w", Func("Kb1Func6"),300,100,2) ; tapTime, holdTime, maxTaps, prefixes
;AHI.SubscribeKey(keyboardId, GetKeySC("w"), true, Func("KeyEvent").Bind(8))
AHI.SubscribeKey(keyboardId, GetKeySC("e"), true, Func("KeyEvent").Bind(9))
AHI.SubscribeKey(keyboardId, GetKeySC("r"), true, Func("KeyEvent").Bind(10))
AHI.SubscribeKey(keyboardId, GetKeySC("CapsLock"), true, Func("KeyEvent").Bind(11))
AHI.SubscribeKey(keyboardId, GetKeySC("a"), true, Func("KeyEvent").Bind(12))
AHI.SubscribeKey(keyboardId, GetKeySC("s"), true, Func("KeyEvent").Bind(13))
AHI.SubscribeKey(keyboardId, GetKeySC("d"), true, Func("KeyEvent").Bind(14))
AHI.SubscribeKey(keyboardId, GetKeySC("f"), true, Func("KeyEvent").Bind(15))
AHI.SubscribeKey(keyboardId, GetKeySC("LShift"), true, Func("KeyEvent").Bind(16))
AHI.SubscribeKey(keyboardId, GetKeySC("z"), true, Func("KeyEvent").Bind(17))
AHI.SubscribeKey(keyboardId, GetKeySC("x"), true, Func("KeyEvent").Bind(18))
AHI.SubscribeKey(keyboardId, GetKeySC("c"), true, Func("KeyEvent").Bind(19))
AHI.SubscribeKey(keyboardId, GetKeySC("Space"), true, Func("KeyEvent").Bind(20))
AHI.SubscribeKey(keyboardId, GetKeySC("LAlt"), true, Func("KeyEvent").Bind(21))
AHI.SubscribeKey(keyboardId, GetKeySC("Left"), true, Func("KeyEvent").Bind(22))
AHI.SubscribeKey(keyboardId, GetKeySC("Right"), true, Func("KeyEvent").Bind(23))
AHI.SubscribeKey(keyboardId, GetKeySC("Up"), true, Func("KeyEvent").Bind(24))
AHI.SubscribeKey(keyboardId, GetKeySC("Down"), true, Func("KeyEvent").Bind(25))
AHI.SubscribeMouseButton(MouseId, GetKeySC("1"), true, Func("MouseEvent").Bind(26))
;AHI.SubscribeMouseButton(MouseId, GetKeySC("4"), true, Func("WheelEvent1"))
AHI.SubscribeMouseButton(MouseId, GetKeySC("4"), true, Func("WheelEvent2"))
return
KeyEvent(btn, state){
static btnStates := {}
if (btnStates![btn])
return ; Filter repeats
btnStates[btn] := state
myStick.SetBtn(state, btn)
}
;below is replaced by Kb1Func1-5 and kept as a fallback
KeyEvent2(btn, state){
if btn = 1
dbtn := (btn +28)
if btn = 2
dbtn := (btn +28)
if btn = 4
dbtn := (btn +27)
if btn = 5
dbtn := (btn +27)
static btnStates := {}
if (btnStates![btn])
return ; Filter repeats
btnStates[btn] := state
; ToolTip % "State: " state " Button: " btn
myStick.SetBtn(state, btn)
myStick.SetBtn(state, dbtn)
}
MouseEvent(btn, state){
static btnStates := {}
if (btnStates![btn])
return ; Filter repeats
btnStates[btn] := state
myStick.SetBtn(state, btn)
}
;below is replaced by WheelEvent2 and kept as a fallback
WheelEvent1(state){
if state = 1
myStick.SetBtn(1, 27)
if state = -1
myStick.SetBtn(1, 28)
sleep 50
myStick.SetBtn(0, 27)
myStick.SetBtn(0, 28)
}
WheelEvent2(state){
if newstate > 32767
newstate = 32768
if newstate < 1
newstate = 0
newstate = % newstate + (state*2500)
;ToolTip % "State: " state " NewState: " newstate
myStick.SetAxisByIndex(newstate, 7)
sleep 100
newstate := 16384
myStick.SetAxisByIndex(newstate, 7)
}
Kb1Func1(isHold, taps, state){
if taps = 1
{
btn := 1
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
if taps = 2
{
btn := 27
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
}
Kb1Func2(isHold, taps, state){
if taps = 1
{
btn := 2
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
if taps = 2
{
btn := 28
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
}
Kb1Func3(isHold, taps, state){
if taps = 1
{
btn := 3
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
if taps = 2
{
btn := 29
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
}
Kb1Func4(isHold, taps, state){
if taps = 1
{
btn := 4
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
if taps = 2
{
btn := 30
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
}
Kb1Func5(isHold, taps, state){
if taps = 1
{
btn := 5
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
if taps = 2
{
btn := 31
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
}
Kb1Func6(isHold, taps, state){
if taps = 1
{
btn := 8
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
if taps = 2
{
btn := 32
myStick.SetBtn(state, btn)
if state = -1
state := 0
myStick.SetBtn(state, btn)
;ToolTip % "KB 1 Key " btn "`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
}
^Esc::
ExitApp
If anything, use this script as an example of one way of putting it together. It may not be a good example or even a correct example, but it is an example nonetheless.
Thanks very much for the libraries and your help.
Splat