I'm trying to use HID Macros to combine left and right brake values to the slider axis on the X52. I can trigger scripts on the macros tab with keys and buttons, but not continually or with axis changes as in Example 3 on http://www.hidmacros.eu/scripting.php#example No matter what I do I cannot get the scripts in the script tab to run.
here's the simple code, I have. My guess is that I just don't know what I'm doing!
HIDMacros.RegisterFSXVariable "BRAKE LEFT POSITION", "position", 5
BrakeValue = HIDMacros.GetFSXVariable("BRAKE LEFT POSITION")
Dim FinalBrake
FinalBrake = BrakeValue
HIDMacros.SetFSXVariable "BRAKE RIGHT POSITION","position", FinalBrake
Thanks, this powerful software is a gift to the simulation world,
Nick
Cannot run rotuines section
Re: Cannot run rotuines section
Where do you have this code? In routines section or in a macro?
Do you have any error message when you compile it or it just doesn't work?
My guess is you have in routines section, but then it's executed only once. This is probably not what you need.
If you need to have it execute on slider axis change, you must wrap this code into procedure and register such procedure for the axis as described here: http://www.hidmacros.eu/scripting.php#axis
Do you have any error message when you compile it or it just doesn't work?
My guess is you have in routines section, but then it's executed only once. This is probably not what you need.
If you need to have it execute on slider axis change, you must wrap this code into procedure and register such procedure for the axis as described here: http://www.hidmacros.eu/scripting.php#axis
Petr Medek
LUAmacros author
LUAmacros author
Re: Cannot run rotuines section
I have it in routines and I thought that it might run only once, so I added the register event and it looked like this just for testing purposes:
Sub AxisXChange()
HIDMacros.FSXtext "It Worked!"
end sub
HIDMacros.RegisterAxisEvent "Saitek X52 Flight Controller", "X", "AxisXChange", 5
That didn't work either. I also tried it with (dev, axis, val) as the parameters as in the example and that didn't work. I have a fair amount of programming experience, but not with VB5, so that doesn't help.
Thanks for the response!
EDIT:
Actually, I just found something else! In the error log, it said it didn't know the device "Saitek X52 Flight Controller" and that's because it has a different name on my system! It should have been "Saitek X52 Flight Control System"!
Now it works!
Well, I hope I've helped someone else in the process. Thanks again! Now I get to enjoy this great software.
Sub AxisXChange()
HIDMacros.FSXtext "It Worked!"
end sub
HIDMacros.RegisterAxisEvent "Saitek X52 Flight Controller", "X", "AxisXChange", 5
That didn't work either. I also tried it with (dev, axis, val) as the parameters as in the example and that didn't work. I have a fair amount of programming experience, but not with VB5, so that doesn't help.
Thanks for the response!
EDIT:
Actually, I just found something else! In the error log, it said it didn't know the device "Saitek X52 Flight Controller" and that's because it has a different name on my system! It should have been "Saitek X52 Flight Control System"!
Now it works!
Well, I hope I've helped someone else in the process. Thanks again! Now I get to enjoy this great software.
Re: Cannot run rotuines section
Sorry, now I have another problem. Here's my code, when I ask it to print the value of the axis it's correct, but the brake variable being set remains constant at something like 0.041123141534626456. Something else weird, the button I have set to brake on/off on my joystick using the FSX menu no longer works with this code.
Sub BrakeChange(dev, axis, val)
Dim BrakeValue
BrakeValue = HIDMacros.GetAxis("Saitek X52 Flight Control System", "Slider1")
HIDMacros.SetFSXVariable "BRAKE RIGHT POSITION", "position", BrakeValue
HIDMacros.SetFSXVariable "BRAKE LEFT POSITION", "position", BrakeValue
HIDMacros.FSXText( HIDMacros.GetFSXVariable( "BRAKE RIGHT POSITION" ))
end sub
HIDMacros.RegisterAxisEvent "Saitek X52 Flight Control System", "Slider1", "BrakeChange", 5
Thanks again,
Nick
Sub BrakeChange(dev, axis, val)
Dim BrakeValue
BrakeValue = HIDMacros.GetAxis("Saitek X52 Flight Control System", "Slider1")
HIDMacros.SetFSXVariable "BRAKE RIGHT POSITION", "position", BrakeValue
HIDMacros.SetFSXVariable "BRAKE LEFT POSITION", "position", BrakeValue
HIDMacros.FSXText( HIDMacros.GetFSXVariable( "BRAKE RIGHT POSITION" ))
end sub
HIDMacros.RegisterAxisEvent "Saitek X52 Flight Control System", "Slider1", "BrakeChange", 5
Thanks again,
Nick
Re: Cannot run rotuines section
You don't have to call GetAxis in your sub - you should have the value in val parameter.
If I remember well the axis value comes in range 0 and 65535. Is it fine to send this value as brake position (I didn't check SDK, just possible problem).
The GetFSXvariable call returns last value that SimConnect sent to HIDMacros. Those value messages can have delays, so if you call GetFSXvariable just after SetFSXvariable it may happen value is not yet known in HIDmacros. You can try to set some fixed value and later find out if it was set... e.g. setting in one macro and reading in different. In short: there's some debugging needed, that's what I would do anyway.
Regarding brake button: I had the same experience in FSX - when I assigned brakes to axis then button didn't work any more. It was FSX behavior, not related to HIDmacros. So check in FSX if brake is assigned only to button, not axis.
If I remember well the axis value comes in range 0 and 65535. Is it fine to send this value as brake position (I didn't check SDK, just possible problem).
The GetFSXvariable call returns last value that SimConnect sent to HIDMacros. Those value messages can have delays, so if you call GetFSXvariable just after SetFSXvariable it may happen value is not yet known in HIDmacros. You can try to set some fixed value and later find out if it was set... e.g. setting in one macro and reading in different. In short: there's some debugging needed, that's what I would do anyway.
Regarding brake button: I had the same experience in FSX - when I assigned brakes to axis then button didn't work any more. It was FSX behavior, not related to HIDmacros. So check in FSX if brake is assigned only to button, not axis.
Petr Medek
LUAmacros author
LUAmacros author
Re: Cannot run rotuines section
Oh, I had a divide by two at the end of that line to knock it down to the 32k accepted position value, but I deleted it while debugging. I read about how the GetFSXVariable is message based from simconeect, but I didn't really expect it to stay at a constant value. I'll keep trying when I get home. There was also something else weird that while running FSX even if I didn't move any controls there would be a ERR:UNKNOWN NAME error in the console. Not sure what it meant because all my code compiled without errors. When I tried putting it in the test window I kept getting syntax errors on the Sub line, but even the examples copy-pasted from the website produced the same errors.