mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2025-12-06 07:12:01 +01:00
This adds a Steam Shortcuts, Desktop Mode, and X360 Emulation - Supports all Steam Shortcuts (including on-screen keyboard, and brightness) - Supports Desktop mode (with a scroll on left pad and left stick), and trackpoint (on right stick) - Supports X360 mode: hold Options for 1s to switch between Desktop and X360 - Holding Steam button enables Desktop like controls and stops passing all inputs to X360
96 lines
2.4 KiB
C#
96 lines
2.4 KiB
C#
using WindowsInput;
|
|
|
|
namespace SteamController.Devices
|
|
{
|
|
public class KeyboardController : IDisposable
|
|
{
|
|
InputSimulator simulator = new InputSimulator();
|
|
|
|
HashSet<VirtualKeyCode> keyCodes = new HashSet<VirtualKeyCode>();
|
|
HashSet<VirtualKeyCode> lastKeyCodes = new HashSet<VirtualKeyCode>();
|
|
|
|
public KeyboardController()
|
|
{
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public bool this[VirtualKeyCode button]
|
|
{
|
|
get { return keyCodes.Contains(button); }
|
|
set
|
|
{
|
|
if (value)
|
|
keyCodes.Add(button);
|
|
else
|
|
keyCodes.Remove(button);
|
|
}
|
|
}
|
|
|
|
public VirtualKeyCode[] DownKeys
|
|
{
|
|
get { return keyCodes.ToArray(); }
|
|
}
|
|
|
|
internal void BeforeUpdate()
|
|
{
|
|
lastKeyCodes = keyCodes;
|
|
keyCodes = new HashSet<VirtualKeyCode>();
|
|
}
|
|
|
|
internal void Update()
|
|
{
|
|
try
|
|
{
|
|
// Key Up: it is missing now
|
|
var keyUp = lastKeyCodes.Except(keyCodes).ToArray();
|
|
if (keyUp.Any())
|
|
simulator.Keyboard.KeyUp(keyUp);
|
|
|
|
// Key Down: new keys being down
|
|
var keyDown = keyCodes.Except(lastKeyCodes).ToArray();
|
|
if (keyDown.Any())
|
|
simulator.Keyboard.KeyUp(keyDown);
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
}
|
|
}
|
|
|
|
public void KeyPress(params VirtualKeyCode[] keyCodes)
|
|
{
|
|
try
|
|
{
|
|
simulator.Keyboard.KeyPress(keyCodes);
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
}
|
|
}
|
|
|
|
public void KeyPress(VirtualKeyCode modifierKey, params VirtualKeyCode[] keyCodes)
|
|
{
|
|
try
|
|
{
|
|
simulator.Keyboard.ModifiedKeyStroke(modifierKey, keyCodes);
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
}
|
|
}
|
|
|
|
public void KeyPress(IEnumerable<VirtualKeyCode> modifierKeys, params VirtualKeyCode[] keyCodes)
|
|
{
|
|
try
|
|
{
|
|
simulator.Keyboard.ModifiedKeyStroke(modifierKeys, keyCodes);
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|