Add Send functions

device-handlers
Clive Galway 2 years ago
parent aa1f81f5b6
commit f37055ecf8

@ -26,6 +26,27 @@ namespace AutoHotInterception.DeviceHandlers
}
}
/// <summary>
/// Sends a keyboard key event
/// </summary>
/// <param name="code">The ScanCode to send</param>
/// <param name="state">The State to send (1 = pressed, 0 = released)</param>
public void SendKeyEvent(ushort code, int state)
{
var st = 1 - state;
var stroke = new ManagedWrapper.Stroke();
if (code > 255)
{
code -= 256;
if (code != 54) // RShift has > 256 code, but state is 0/1
st += 2;
}
stroke.key.code = code;
stroke.key.state = (ushort)st;
ManagedWrapper.Send(DeviceContext, DeviceId, ref stroke, 1);
}
// ScanCode notes: https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
public override void ProcessStroke(ManagedWrapper.Stroke stroke)
{

@ -33,6 +33,9 @@ namespace AutoHotInterception.DeviceHandlers
IsFiltered = true;
}
/// <summary>
/// Unsubscribes from absolute mouse movement
/// </summary>
public void UnsubscribeMouseMoveAbsolute()
{
if (_mouseMoveAbsoluteMapping == null) return;
@ -59,6 +62,9 @@ namespace AutoHotInterception.DeviceHandlers
IsFiltered = true;
}
/// <summary>
/// Unsubscribes from relative mouse movement
/// </summary>
public void UnsubscribeMouseMoveRelative()
{
if (_mouseMoveRelativeMapping == null) return;
@ -85,6 +91,62 @@ namespace AutoHotInterception.DeviceHandlers
}
}
/// <summary>
/// Sends Mouse button events
/// </summary>
/// <param name="btn">Button ID to send</param>
/// <param name="state">State of the button</param>
/// <returns></returns>
public void SendMouseButtonEvent(int btn, int state)
{
var stroke = HelperFunctions.MouseButtonAndStateToStroke(btn, state);
ManagedWrapper.Send(DeviceContext, DeviceId, ref stroke, 1);
}
/// <summary>
/// Same as <see cref="SendMouseButtonEvent" />, but sends button events in Absolute mode (with coordinates)
/// </summary>
/// <param name="btn">Button ID to send</param>
/// <param name="state">State of the button</param>
/// <param name="x">X position</param>
/// <param name="y">Y position</param>
public void SendMouseButtonEventAbsolute(int btn, int state, int x, int y)
{
var stroke = HelperFunctions.MouseButtonAndStateToStroke(btn, state);
stroke.mouse.x = x;
stroke.mouse.y = y;
stroke.mouse.flags = (ushort)ManagedWrapper.MouseFlag.MouseMoveAbsolute;
ManagedWrapper.Send(DeviceContext, DeviceId, ref stroke, 1);
}
/// <summary>
/// Sends Absolute Mouse Movement
/// Note: Creating a new stroke seems to make Absolute input become relative to main monitor
/// Calling Send on an actual stroke from an Absolute device results in input relative to all monitors
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public void SendMouseMoveAbsolute(int x, int y)
{
var stroke = new ManagedWrapper.Stroke
{ mouse = { x = x, y = y, flags = (ushort)ManagedWrapper.MouseFlag.MouseMoveAbsolute } };
ManagedWrapper.Send(DeviceContext, DeviceId, ref stroke, 1);
}
/// <summary>
/// Sends Relative Mouse Movement
/// </summary>
/// <param name="x">X movement</param>
/// <param name="y">Y movement</param>
/// <returns></returns>
public void SendMouseMoveRelative(int x, int y)
{
var stroke = new ManagedWrapper.Stroke
{ mouse = { x = x, y = y, flags = (ushort)ManagedWrapper.MouseFlag.MouseMoveRelative } };
ManagedWrapper.Send(DeviceContext, DeviceId, ref stroke, 1);
}
public override void ProcessStroke(ManagedWrapper.Stroke stroke)
{
var hasSubscription = false;

@ -345,7 +345,7 @@ namespace AutoHotInterception
#region Input Synthesis
/// <summary>
/// Sends a keyboard key event
/// Sends a keyboard key event
/// </summary>
/// <param name="id">The ID of the Keyboard to send as</param>
/// <param name="code">The ScanCode to send</param>
@ -353,50 +353,37 @@ namespace AutoHotInterception
public void SendKeyEvent(int id, ushort code, int state)
{
HelperFunctions.IsValidDeviceId(false, id);
var st = 1 - state;
var stroke = new ManagedWrapper.Stroke();
if (code > 255)
{
code -= 256;
if (code != 54) // RShift has > 256 code, but state is 0/1
st += 2;
}
stroke.key.code = code;
stroke.key.state = (ushort)st;
ManagedWrapper.Send(DeviceContext, id, ref stroke, 1);
var device = (KeyboardHandler)DeviceHandlers[id];
device.SendKeyEvent(code, state);
}
/// <summary>
/// Sends Mouse button events
/// Sends Mouse button events
/// </summary>
/// <param name="id"></param>
/// <param name="btn"></param>
/// <param name="state"></param>
/// <param name="btn">Button ID to send</param>
/// <param name="state">State of the button</param>
/// <returns></returns>
public void SendMouseButtonEvent(int id, int btn, int state)
{
HelperFunctions.IsValidDeviceId(true, id);
var stroke = HelperFunctions.MouseButtonAndStateToStroke(btn, state);
ManagedWrapper.Send(DeviceContext, id, ref stroke, 1);
var device = (MouseHandler)DeviceHandlers[id];
device.SendMouseButtonEvent(btn, state);
}
/// <summary>
/// Same as <see cref="SendMouseButtonEvent" />, but sends button events in Absolute mode (with coordinates)
/// Same as <see cref="SendMouseButtonEvent" />, but sends button events in Absolute mode (with coordinates)
/// </summary>
/// <param name="id"></param>
/// <param name="btn"></param>
/// <param name="state"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="id">ID of the mouse</param>
/// <param name="btn">Button ID to send</param>
/// <param name="state">State of the button</param>
/// <param name="x">X position</param>
/// <param name="y">Y position</param>
public void SendMouseButtonEventAbsolute(int id, int btn, int state, int x, int y)
{
var stroke = HelperFunctions.MouseButtonAndStateToStroke(btn, state);
stroke.mouse.x = x;
stroke.mouse.y = y;
stroke.mouse.flags = (ushort)ManagedWrapper.MouseFlag.MouseMoveAbsolute;
ManagedWrapper.Send(DeviceContext, id, ref stroke, 1);
HelperFunctions.IsValidDeviceId(true, id);
var device = (MouseHandler)DeviceHandlers[id];
device.SendMouseButtonEventAbsolute(btn, state, x, y);
}
public void SendMouseMove(int id, int x, int y)
@ -407,9 +394,9 @@ namespace AutoHotInterception
/// <summary>
/// Sends Relative Mouse Movement
/// </summary>
/// <param name="id"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="id">The id of the mouse</param>
/// <param name="x">X movement</param>
/// <param name="y">Y movement</param>
/// <returns></returns>
public void SendMouseMoveRelative(int id, int x, int y)
{
@ -432,10 +419,9 @@ namespace AutoHotInterception
public void SendMouseMoveAbsolute(int id, int x, int y)
{
HelperFunctions.IsValidDeviceId(true, id);
var device = (MouseHandler)DeviceHandlers[id];
var stroke = new ManagedWrapper.Stroke
{ mouse = { x = x, y = y, flags = (ushort)ManagedWrapper.MouseFlag.MouseMoveAbsolute } };
ManagedWrapper.Send(DeviceContext, id, ref stroke, 1);
device.SendMouseMoveAbsolute(x, y);
}
#endregion

Loading…
Cancel
Save