I noticed some heavy lag at 5fps or 10fps too, but it went away with 30fps and is not noticeable with high fps (6000). I am not sure why you would experience it so strongly (1 second, wtf). I tested a bit with uncommenting Log lines to see whats going on in the console.
AddKeyIndex is mostly used for keyboards on other platforms, e.g. in XNA everything can be handled in the update loop (polling). It shouldn't matter much if it is added in the key up/down events of WindowsKeyboard.cs because the keys are added to the keysUp and keysDowns lists anyway and those will call the AddKeyIndex method anyway. I have commented them out and see no difference in WPF, so it will stay commented out (simpler code is always better).
Please note that I tried to test the keyboard with logging enabled and with 5fps to see whats going on, I also reduced input lag because my GPU rendered several frames ahead and this makes things confusing ^^
Code:
// Limit to 5 fps for easier state checking.
Settings.Extra.LimitFramerateNumber = 5;
Settings.Extra.ReduceInputLag = true;
After testing for another hour this evening and fixing some minor issues along the way it turned out the
Update code was not broken, neither was the
LowLevelCaptureKey hook function. The problem was apparent with 1 fps as way more (10-20x) events arrived at the LowLevelCaptureKey function than the app could handle. It seemed to lag 20-30 seconds behind, so this is the same issue you were experiencing just a much worse delay with 1 update tick per second. The trick here is to not let Windows call the
LowLevelCaptureKey hook function so often. I just limited it to the current executing input thread and the problem went fully away and the code works fine now
Code:
// Set Hook of Keyboard Process for current module and thread.
lowLevelKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
keyboardProcessObject, GetModuleHandle(currentModule.ModuleName),
(uint)GetCurrentThreadId());
Hope this helps.
Edited by user Sunday, May 6, 2012 11:53:24 PM(UTC)
| Reason: Not specified