Bug fix. Realized the first pass that tried to pile up would have set _doingWork = false and the subsequent operation would have been allowed to set key state.

master
Sean McArdle 2017-03-17 11:15:42 -07:00
parent 172549e4ce
commit 83d5d65fa3
1 changed files with 23 additions and 27 deletions

View File

@ -50,37 +50,33 @@ namespace KeyWatch__
bool watching = _manageCaps || _manageNum || _manageScroll;
if (!watching) { return; }
if (!watching) return; // nothing to manage, who cares
if (_doingWork) return; // already working on things, skip
if (!_doingWork) {
_doingWork = true;
// Set desired key state
if (_manageNum) {
if (_numlockSelection != null) {
if ((_numlockSelection == "Enabled" && !NumLock) ||
(_numlockSelection == "Disabled" && NumLock)) {
_sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.NUMLOCK);
Trace.WriteLine(String.Format("{0} - enable Numlock", DateTime.Now));
}
_doingWork = true;
// Set desired key state
if (_manageNum) {
if (_numlockSelection != null) {
if ((_numlockSelection == "Enabled" && !NumLock) ||
(_numlockSelection == "Disabled" && NumLock)) {
_sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.NUMLOCK);
Trace.WriteLine(String.Format("{0} - enable Numlock", DateTime.Now));
}
}
if (_manageCaps) {
if ((_capslockSelection == "Enabled" && !CapsLock) ||
(_capslockSelection == "Disabled" && CapsLock)) {
_sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.CAPITAL);
Trace.WriteLine(String.Format("{0} - disable Capslock", DateTime.Now));
}
}
if (_manageScroll) {
if ((_scrolllockSelection == "Enabled" && !ScrollLock) ||
(_scrolllockSelection == "Disabled" && ScrollLock))
_sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SCROLL);
Trace.WriteLine(String.Format("{0} - disable Scrolllock", DateTime.Now));
}
}
if (_manageCaps) {
if ((_capslockSelection == "Enabled" && !CapsLock) ||
(_capslockSelection == "Disabled" && CapsLock)) {
_sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.CAPITAL);
Trace.WriteLine(String.Format("{0} - disable Capslock", DateTime.Now));
}
}
if (_manageScroll) {
if ((_scrolllockSelection == "Enabled" && !ScrollLock) ||
(_scrolllockSelection == "Disabled" && ScrollLock))
_sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SCROLL);
Trace.WriteLine(String.Format("{0} - disable Scrolllock", DateTime.Now));
}
_doingWork = false;
}