SEBWIN-312: Ensured system task view is never activated and improved pause mechanism for activators.

This commit is contained in:
dbuechel 2019-11-21 08:45:38 +01:00
parent d7a4dc8782
commit 0a939e19ac
7 changed files with 56 additions and 36 deletions

View file

@ -69,7 +69,7 @@ namespace SafeExamBrowser.Monitoring.Keyboard
block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.Escape && !settings.AllowAltEsc;
block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.F4 && !settings.AllowAltF4;
block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.Space;
block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.Tab && !settings.AllowAltTab;
block |= modifier.HasFlag(KeyModifier.Alt) && key == Key.Tab;
block |= modifier.HasFlag(KeyModifier.Ctrl) && key == Key.Escape && !settings.AllowCtrlEsc;
if (block)

View file

@ -29,16 +29,10 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
this.logger = logger;
}
public void Pause()
{
Paused = true;
}
public void Resume()
protected override void OnBeforeResume()
{
A = false;
LeftWindows = false;
Paused = false;
}
protected override bool Process(Key key, KeyModifier modifier, KeyState state)

View file

@ -31,15 +31,9 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
this.nativeMethods = nativeMethods;
}
public void Pause()
{
Paused = true;
}
public void Resume()
protected override void OnBeforeResume()
{
isDown = false;
Paused = false;
}
protected override bool Process(MouseButton button, MouseButtonState state, MouseInformation info)

View file

@ -15,10 +15,9 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
{
public abstract class KeyboardActivator
{
private INativeMethods nativeMethods;
private Guid? hookId;
protected bool Paused { get; set; }
private INativeMethods nativeMethods;
private bool paused;
protected KeyboardActivator(INativeMethods nativeMethods)
{
@ -27,6 +26,18 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
protected abstract bool Process(Key key, KeyModifier modifier, KeyState state);
public void Pause()
{
OnBeforePause();
paused = true;
}
public void Resume()
{
OnBeforeResume();
paused = false;
}
public void Start()
{
hookId = nativeMethods.RegisterKeyboardHook(KeyboardHookCallback);
@ -40,9 +51,17 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
}
}
protected virtual void OnBeforePause()
{
}
protected virtual void OnBeforeResume()
{
}
private bool KeyboardHookCallback(int keyCode, KeyModifier modifier, KeyState state)
{
if (!Paused)
if (!paused)
{
return Process(KeyInterop.KeyFromVirtualKey(keyCode), modifier, state);
}

View file

@ -17,7 +17,7 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
{
public class TaskViewKeyboardActivator : KeyboardActivator, ITaskViewActivator
{
private bool Activated, BlockActivation, LeftShift, Tab;
private bool Activated, LeftShift, Tab;
private ILogger logger;
public event ActivatorEventHandler Deactivated;
@ -29,14 +29,22 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
this.logger = logger;
}
public void Pause()
protected override void OnBeforePause()
{
BlockActivation = true;
if (Activated)
{
logger.Debug("Auto-deactivation.");
Deactivated?.Invoke();
}
Activated = false;
}
public void Resume()
protected override void OnBeforeResume()
{
BlockActivation = false;
Activated = false;
LeftShift = false;
Tab = false;
}
protected override bool Process(Key key, KeyModifier modifier, KeyState state)
@ -73,7 +81,7 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
var isActivation = Tab && changed;
if (isActivation && !BlockActivation)
if (isActivation)
{
Activated = true;

View file

@ -27,17 +27,11 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
this.logger = logger;
}
public void Pause()
{
Paused = true;
}
public void Resume()
protected override void OnBeforeResume()
{
Q = false;
LeftCtrl = false;
RightCtrl = false;
Paused = false;
}
protected override bool Process(Key key, KeyModifier modifier, KeyState state)

View file

@ -14,18 +14,29 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
{
public abstract class TouchActivator
{
private INativeMethods nativeMethods;
private Guid? hookId;
protected bool Paused { get; set; }
private INativeMethods nativeMethods;
protected bool paused;
protected TouchActivator(INativeMethods nativeMethods)
{
this.nativeMethods = nativeMethods;
}
protected abstract void OnBeforeResume();
protected abstract bool Process(MouseButton button, MouseButtonState state, MouseInformation info);
public void Pause()
{
paused = true;
}
public void Resume()
{
OnBeforeResume();
paused = false;
}
public void Start()
{
hookId = nativeMethods.RegisterMouseHook(MouseHookCallback);
@ -41,7 +52,7 @@ namespace SafeExamBrowser.UserInterface.Shared.Activators
private bool MouseHookCallback(MouseButton button, MouseButtonState state, MouseInformation info)
{
if (!Paused && info.IsTouch)
if (!paused && info.IsTouch)
{
return Process(button, state, info);
}