mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-04-06 23:03:59 +00:00
Add SteamController implementation
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
This commit is contained in:
parent
203338b669
commit
ecbd0407c0
41 changed files with 2486 additions and 34 deletions
95
SteamController/Devices/KeyboardController.cs
Normal file
95
SteamController/Devices/KeyboardController.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue