Added ability to use Mouse 4 and Mouse 5 as hotkeys

This commit is contained in:
Nate Nichols
2023-04-17 12:08:33 -05:00
committed by Gustas
parent 4f7a01a291
commit 8f511a3bb6
3 changed files with 62 additions and 31 deletions

View File

@@ -112,43 +112,68 @@ namespace OpenRA.Platforms.Default
}
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
{
if (pendingMotion != null)
{
inputHandler.OnMouseInput(pendingMotion.Value);
pendingMotion = null;
}
var button = MakeButton(e.button.button);
lastButtonBits |= button;
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
var pos = EventPosition(device, input.X, input.Y);
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Down, button, pos, int2.Zero, mods,
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
break;
}
case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
{
if (pendingMotion != null)
// Mouse 1, Mouse 2 and Mouse 3 are handled as mouse inputs
// Mouse 4 and Mouse 5 are treated as (pseudo) keyboard inputs
if (e.button.button == SDL.SDL_BUTTON_LEFT ||
e.button.button == SDL.SDL_BUTTON_MIDDLE ||
e.button.button == SDL.SDL_BUTTON_RIGHT)
{
inputHandler.OnMouseInput(pendingMotion.Value);
pendingMotion = null;
if (pendingMotion != null)
{
inputHandler.OnMouseInput(pendingMotion.Value);
pendingMotion = null;
}
var button = MakeButton(e.button.button);
if (e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN)
lastButtonBits |= button;
else
lastButtonBits &= ~button;
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
var pos = EventPosition(device, input.X, input.Y);
if (e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN)
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Down, button, pos, int2.Zero, mods,
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
else
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Up, button, pos, int2.Zero, mods,
MultiTapDetection.InfoFromMouse(e.button.button)));
}
var button = MakeButton(e.button.button);
lastButtonBits &= ~button;
if (e.button.button == SDL.SDL_BUTTON_X1 ||
e.button.button == SDL.SDL_BUTTON_X2)
{
Keycode keyCode;
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
var pos = EventPosition(device, input.X, input.Y);
if (e.button.button == SDL.SDL_BUTTON_X1)
keyCode = Keycode.MOUSE4;
else
keyCode = Keycode.MOUSE5;
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Up, button, pos, int2.Zero, mods,
MultiTapDetection.InfoFromMouse(e.button.button)));
var type = e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN ?
KeyInputEvent.Down : KeyInputEvent.Up;
var tapCount = e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN ?
MultiTapDetection.DetectFromKeyboard(keyCode, mods) :
MultiTapDetection.InfoFromKeyboard(keyCode, mods);
var keyEvent = new KeyInput
{
Event = type,
Key = keyCode,
Modifiers = mods,
UnicodeChar = '?',
MultiTapCount = tapCount,
IsRepeat = e.key.repeat != 0
};
inputHandler.OnKeyInput(keyEvent);
}
break;
}