Hi all,
I did some more benchmarking on kb2xi to try to understand the behavior of Injustice 2 (and probably MK11). Some conclusions:
- I register kb2xi to listen to keyboard events, and key events are sequential notified to kb2xi. On my setup, if I press 2 keys at the same time, kb2xi receives the 2 events with a 7ms delay between them. Even If I disable everything (no more virtual pads) and only measure the time between key press events, I cannot get uneder 7ms
- If a game runs at 60fps, that's 17ms between each frame
- on average, this must explain why Injustice 2 sees 2 button discrete presses instead of two simultaneous presses
I said earlier that handling the key event took 0ms. I since used a more precise timer, and it takes on average 123 nanoseconds. So maybe that on some setups it takes more time.
By default, I log every key press and release, to aid configuration. Logging is not very expensive, but disabling it brings the average down to 83 ns.
So I've made the following changes:
- Logging by default now only logs when unmapped keys are pressed (which I think is the main thing that helps during configuration)
- I optimized kb2xi a bit: I'm down to 73ns on average to handle a key
It seems to help Injustice 2 a bit, but then again it's not perfect and I've tried so many times the throw (X+A) in practice mode that my view is biased.
For those having problems with Injustice 2/MK11, could you please test the following version:
https://kb2xi.schwingsk.net/builds/build/dist/Keyboard2Xinput.zip?
For bonus points, after testing, edit Keyboard2XinputGui.exe.config and edit line 28 to enable performance logging:
<level value="Info" />
becomes
<level value="Debug" />
relaunch kb2xi and press X+A repeatedly (no need to be in-game). Send me the results to I can see the average time between two key events. Or you can look in k2x.log and you'll find lines like:
2020-06-13 19:35:30,072 [1] DEBUG Keyboard2XinputLib.Keyboard2Xinput- pad1 X down
2020-06-13 19:35:30,072 [1] DEBUG Keyboard2XinputGui.Keyboard2XinputGui- handling key took 0,1226 ms ; timestamp: 1212327635,6983ms
2020-06-13 19:35:30,079 [1] DEBUG Keyboard2XinputLib.Keyboard2Xinput- pad1 A down
2020-06-13 19:35:30,079 [1] DEBUG Keyboard2XinputGui.Keyboard2XinputGui- handling key took 0,1194 ms ; timestamp: 1212327642,6879ms
[/code]
The difference between the 2 dates ms (here 072and 079) is the number of ms between two key events. As I said, on average this is 7ms on my setup. Sometimes it's 0, but it's rare. If you have some time, please report this time so I can know if times vary between setups.
Next steps are to find a System call o(or a library) that allows me to do what I currently do (i.e. intercept keys) but doewn't have so much time between the events it sends. I'm not very hopefull, but you never know
Hope that helps some of you, and thanks for reading (don't hesitate to react if this is too obscure, I'lle try to explain it better
)!