Restore SEBPatch
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System.Windows.Input;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Shared.Activators
|
||||
{
|
||||
public class ActionCenterKeyboardActivator : KeyboardActivator, IActionCenterActivator
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private bool A, LeftWindows;
|
||||
|
||||
public event ActivatorEventHandler Activated { add { } remove { } }
|
||||
public event ActivatorEventHandler Deactivated { add { } remove { } }
|
||||
public event ActivatorEventHandler Toggled;
|
||||
|
||||
public ActionCenterKeyboardActivator(ILogger logger, INativeMethods nativeMethods) : base(nativeMethods)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
protected override void OnBeforeResume()
|
||||
{
|
||||
A = false;
|
||||
LeftWindows = false;
|
||||
}
|
||||
|
||||
protected override bool Process(Key key, KeyModifier modifier, KeyState state)
|
||||
{
|
||||
var changed = false;
|
||||
var pressed = state == KeyState.Pressed;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case Key.A:
|
||||
changed = A != pressed;
|
||||
A = pressed;
|
||||
break;
|
||||
case Key.LWin:
|
||||
changed = LeftWindows != pressed;
|
||||
LeftWindows = pressed;
|
||||
break;
|
||||
}
|
||||
|
||||
if (A && LeftWindows && changed)
|
||||
{
|
||||
logger.Debug("Detected toggle sequence for action center.");
|
||||
Toggled?.Invoke();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Shared.Activators
|
||||
{
|
||||
public class ActionCenterTouchActivator : TouchActivator, IActionCenterActivator
|
||||
{
|
||||
private const int ACTIVATION_INTERVAL = 100;
|
||||
|
||||
private bool isDown;
|
||||
private ILogger logger;
|
||||
private INativeMethods nativeMethods;
|
||||
|
||||
public event ActivatorEventHandler Activated;
|
||||
public event ActivatorEventHandler Deactivated { add { } remove { } }
|
||||
public event ActivatorEventHandler Toggled { add { } remove { } }
|
||||
|
||||
public ActionCenterTouchActivator(ILogger logger, INativeMethods nativeMethods) : base(nativeMethods)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.nativeMethods = nativeMethods;
|
||||
}
|
||||
|
||||
protected override void OnBeforeResume()
|
||||
{
|
||||
isDown = false;
|
||||
}
|
||||
|
||||
protected override bool Process(MouseButton button, MouseButtonState state, MouseInformation info)
|
||||
{
|
||||
var inActivationArea = 0 < info.X && info.X < SystemParameters.PrimaryScreenWidth * 0.1;
|
||||
|
||||
if (button == MouseButton.Left)
|
||||
{
|
||||
if (state == MouseButtonState.Released)
|
||||
{
|
||||
isDown = false;
|
||||
}
|
||||
|
||||
if (state == MouseButtonState.Pressed && inActivationArea)
|
||||
{
|
||||
isDown = true;
|
||||
|
||||
Task.Delay(ACTIVATION_INTERVAL).ContinueWith(async _ =>
|
||||
{
|
||||
for (var t = 0; t < 4; t++)
|
||||
{
|
||||
if (WasActivated())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
await Task.Delay(ACTIVATION_INTERVAL);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool WasActivated()
|
||||
{
|
||||
var (x, y) = nativeMethods.GetCursorPosition();
|
||||
var hasMoved = x > SystemParameters.PrimaryScreenWidth * 0.1;
|
||||
var activate = isDown && hasMoved;
|
||||
|
||||
if (activate)
|
||||
{
|
||||
logger.Debug("Detected activation gesture for action center.");
|
||||
Activated?.Invoke();
|
||||
}
|
||||
|
||||
return activate;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Shared.Activators
|
||||
{
|
||||
public abstract class KeyboardActivator
|
||||
{
|
||||
private Guid? hookId;
|
||||
private INativeMethods nativeMethods;
|
||||
private bool paused;
|
||||
|
||||
protected KeyboardActivator(INativeMethods nativeMethods)
|
||||
{
|
||||
this.nativeMethods = nativeMethods;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (hookId.HasValue)
|
||||
{
|
||||
nativeMethods.DeregisterKeyboardHook(hookId.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnBeforePause()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnBeforeResume()
|
||||
{
|
||||
}
|
||||
|
||||
private bool KeyboardHookCallback(int keyCode, KeyModifier modifier, KeyState state)
|
||||
{
|
||||
if (!paused)
|
||||
{
|
||||
return Process(KeyInterop.KeyFromVirtualKey(keyCode), modifier, state);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System.Windows.Input;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Shared.Activators
|
||||
{
|
||||
public class TaskviewKeyboardActivator : KeyboardActivator, ITaskviewActivator
|
||||
{
|
||||
private bool Activated, LeftShift, Tab;
|
||||
private ILogger logger;
|
||||
|
||||
public event ActivatorEventHandler Deactivated;
|
||||
public event ActivatorEventHandler NextActivated;
|
||||
public event ActivatorEventHandler PreviousActivated;
|
||||
|
||||
public TaskviewKeyboardActivator(ILogger logger, INativeMethods nativeMethods) : base(nativeMethods)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
protected override void OnBeforePause()
|
||||
{
|
||||
if (Activated)
|
||||
{
|
||||
logger.Debug("Auto-deactivation.");
|
||||
Deactivated?.Invoke();
|
||||
}
|
||||
|
||||
Activated = false;
|
||||
}
|
||||
|
||||
protected override void OnBeforeResume()
|
||||
{
|
||||
Activated = false;
|
||||
LeftShift = false;
|
||||
Tab = false;
|
||||
}
|
||||
|
||||
protected override bool Process(Key key, KeyModifier modifier, KeyState state)
|
||||
{
|
||||
/*
|
||||
if (IsDeactivation(modifier))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsActivation(key, modifier, state))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsActivation(Key key, KeyModifier modifier, KeyState state)
|
||||
{
|
||||
var changed = false;
|
||||
var pressed = state == KeyState.Pressed && modifier.HasFlag(KeyModifier.Alt);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case Key.Tab:
|
||||
changed = Tab != pressed;
|
||||
Tab = pressed;
|
||||
break;
|
||||
case Key.LeftShift:
|
||||
changed = LeftShift != pressed;
|
||||
LeftShift = pressed;
|
||||
break;
|
||||
}
|
||||
|
||||
var isActivation = Tab && changed;
|
||||
|
||||
if (isActivation)
|
||||
{
|
||||
Activated = true;
|
||||
|
||||
if (LeftShift)
|
||||
{
|
||||
logger.Debug("Detected sequence for previous instance.");
|
||||
PreviousActivated?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Debug("Detected sequence for next instance.");
|
||||
NextActivated?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
return isActivation;
|
||||
}
|
||||
|
||||
private bool IsDeactivation(KeyModifier modifier)
|
||||
{
|
||||
var isDeactivation = Activated && !modifier.HasFlag(KeyModifier.Alt);
|
||||
|
||||
if (isDeactivation)
|
||||
{
|
||||
Activated = false;
|
||||
LeftShift = false;
|
||||
Tab = false;
|
||||
|
||||
logger.Debug("Detected deactivation sequence.");
|
||||
Deactivated?.Invoke();
|
||||
}
|
||||
|
||||
return isDeactivation;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System.Windows.Input;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Shared.Activators
|
||||
{
|
||||
public class TaskbarKeyboardActivator : KeyboardActivator, ITaskbarActivator
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private bool LeftWindows;
|
||||
|
||||
public event ActivatorEventHandler Activated;
|
||||
|
||||
public TaskbarKeyboardActivator(ILogger logger, INativeMethods nativeMethods) : base(nativeMethods)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
protected override bool Process(Key key, KeyModifier modifier, KeyState state)
|
||||
{
|
||||
/*
|
||||
var changed = false;
|
||||
var pressed = state == KeyState.Pressed;
|
||||
|
||||
if (key == Key.LWin)
|
||||
{
|
||||
changed = LeftWindows != pressed;
|
||||
LeftWindows = pressed;
|
||||
}
|
||||
|
||||
if (LeftWindows && changed)
|
||||
{
|
||||
logger.Debug("Detected activation sequence for taskbar.");
|
||||
Activated?.Invoke();
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System.Windows.Input;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Shell.Events;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Shared.Activators
|
||||
{
|
||||
public class TerminationActivator : KeyboardActivator, ITerminationActivator
|
||||
{
|
||||
private bool Q, LeftCtrl, RightCtrl;
|
||||
private ILogger logger;
|
||||
|
||||
public event ActivatorEventHandler Activated;
|
||||
|
||||
public TerminationActivator(ILogger logger, INativeMethods nativeMethods) : base(nativeMethods)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
protected override void OnBeforeResume()
|
||||
{
|
||||
Q = false;
|
||||
LeftCtrl = false;
|
||||
RightCtrl = false;
|
||||
}
|
||||
|
||||
protected override bool Process(Key key, KeyModifier modifier, KeyState state)
|
||||
{
|
||||
var changed = false;
|
||||
var pressed = state == KeyState.Pressed;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case Key.Q:
|
||||
changed = Q != pressed;
|
||||
Q = pressed;
|
||||
break;
|
||||
case Key.LeftCtrl:
|
||||
changed = LeftCtrl != pressed;
|
||||
LeftCtrl = pressed;
|
||||
break;
|
||||
case Key.RightCtrl:
|
||||
changed = RightCtrl != pressed;
|
||||
RightCtrl = pressed;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Q && (LeftCtrl || RightCtrl) && changed && !modifier.HasFlag(KeyModifier.Alt))
|
||||
{
|
||||
logger.Debug("Detected termination sequence.");
|
||||
Activated?.Invoke();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.WindowsApi.Contracts.Events;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Shared.Activators
|
||||
{
|
||||
public abstract class TouchActivator
|
||||
{
|
||||
private Guid? hookId;
|
||||
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);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (hookId.HasValue)
|
||||
{
|
||||
nativeMethods.DeregisterMouseHook(hookId.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool MouseHookCallback(MouseButton button, MouseButtonState state, MouseInformation info)
|
||||
{
|
||||
if (!paused && info.IsTouch)
|
||||
{
|
||||
return Process(button, state, info);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user