Added ability to use Mouse 4 and Mouse 5 as hotkeys
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -120,6 +120,7 @@ Also thanks to:
|
|||||||
* Mike Gagné (AngryBirdz)
|
* Mike Gagné (AngryBirdz)
|
||||||
* Muh
|
* Muh
|
||||||
* Mustafa Alperen Seki (MustaphaTR)
|
* Mustafa Alperen Seki (MustaphaTR)
|
||||||
|
* Nathan Nichols (cracksmoka420)
|
||||||
* Neil Shivkar (havok13888)
|
* Neil Shivkar (havok13888)
|
||||||
* Nikolay Fomin (netnazgul)
|
* Nikolay Fomin (netnazgul)
|
||||||
* Nooze
|
* Nooze
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
// List of keycodes, duplicated from SDL 2.0.1
|
// List of keycodes. Duplicated from SDL 2.0.1, with the addition
|
||||||
|
// of MOUSE4 and MOUSE5.
|
||||||
public enum Keycode
|
public enum Keycode
|
||||||
{
|
{
|
||||||
UNKNOWN = 0,
|
UNKNOWN = 0,
|
||||||
@@ -252,6 +253,8 @@ namespace OpenRA
|
|||||||
KBDILLUMUP = 280 | (1 << 30),
|
KBDILLUMUP = 280 | (1 << 30),
|
||||||
EJECT = 281 | (1 << 30),
|
EJECT = 281 | (1 << 30),
|
||||||
SLEEP = 282 | (1 << 30),
|
SLEEP = 282 | (1 << 30),
|
||||||
|
MOUSE4 = 283 | (1 << 30),
|
||||||
|
MOUSE5 = 284 | (1 << 30)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class KeycodeExts
|
public static class KeycodeExts
|
||||||
@@ -494,6 +497,8 @@ namespace OpenRA
|
|||||||
{ Keycode.KBDILLUMUP, "KBDIllumUp" },
|
{ Keycode.KBDILLUMUP, "KBDIllumUp" },
|
||||||
{ Keycode.EJECT, "Eject" },
|
{ Keycode.EJECT, "Eject" },
|
||||||
{ Keycode.SLEEP, "Sleep" },
|
{ Keycode.SLEEP, "Sleep" },
|
||||||
|
{ Keycode.MOUSE4, "Mouse 4" },
|
||||||
|
{ Keycode.MOUSE5, "Mouse 5" },
|
||||||
};
|
};
|
||||||
|
|
||||||
public static string DisplayString(Keycode k)
|
public static string DisplayString(Keycode k)
|
||||||
|
|||||||
@@ -112,43 +112,68 @@ namespace OpenRA.Platforms.Default
|
|||||||
}
|
}
|
||||||
|
|
||||||
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
|
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:
|
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);
|
if (pendingMotion != null)
|
||||||
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);
|
if (e.button.button == SDL.SDL_BUTTON_X1 ||
|
||||||
lastButtonBits &= ~button;
|
e.button.button == SDL.SDL_BUTTON_X2)
|
||||||
|
{
|
||||||
|
Keycode keyCode;
|
||||||
|
|
||||||
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
|
if (e.button.button == SDL.SDL_BUTTON_X1)
|
||||||
var pos = EventPosition(device, input.X, input.Y);
|
keyCode = Keycode.MOUSE4;
|
||||||
|
else
|
||||||
|
keyCode = Keycode.MOUSE5;
|
||||||
|
|
||||||
inputHandler.OnMouseInput(new MouseInput(
|
var type = e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN ?
|
||||||
MouseInputEvent.Up, button, pos, int2.Zero, mods,
|
KeyInputEvent.Down : KeyInputEvent.Up;
|
||||||
MultiTapDetection.InfoFromMouse(e.button.button)));
|
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user