2017-08-04 15:20:33 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2017-08-04 15:20:33 +02:00
|
|
|
|
*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Configuration.Contracts.Settings;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
|
|
|
|
using SafeExamBrowser.Monitoring.Contracts;
|
2017-08-04 15:20:33 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Monitoring.Mouse
|
|
|
|
|
{
|
|
|
|
|
public class MouseInterceptor : IMouseInterceptor
|
|
|
|
|
{
|
|
|
|
|
private ILogger logger;
|
2018-02-15 15:42:54 +01:00
|
|
|
|
private MouseSettings settings;
|
2017-08-04 15:20:33 +02:00
|
|
|
|
|
2018-02-15 15:42:54 +01:00
|
|
|
|
public MouseInterceptor(ILogger logger, MouseSettings settings)
|
2017-08-04 15:20:33 +02:00
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.settings = settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Block(MouseButton button, KeyState state)
|
|
|
|
|
{
|
|
|
|
|
var block = false;
|
|
|
|
|
|
2019-01-17 11:12:17 +01:00
|
|
|
|
block |= button == MouseButton.Auxiliary;
|
2019-01-09 16:01:56 +01:00
|
|
|
|
block |= button == MouseButton.Middle && !settings.AllowMiddleButton;
|
|
|
|
|
block |= button == MouseButton.Right && !settings.AllowRightButton;
|
2017-08-04 15:20:33 +02:00
|
|
|
|
|
|
|
|
|
if (block)
|
|
|
|
|
{
|
|
|
|
|
logger.Info($"Blocked {button.ToString().ToLower()} mouse button when {state.ToString().ToLower()}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return block;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|