Created
April 24, 2024 14:45
-
-
Save thenextman/3e1f0eb3ca737d1dfd29bb53af580ae3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Need to enable multi touch input (before connecting). This will enable the MS-RDPEI (extended input) virtual channel if the server supports it | |
` this.Rdp.MultiTouchInput = true` | |
2. Register your pen(s) after connecting. I think you can register up to 10 pens | |
`bool RegisterPen(PenEventType flags, int deviceId, double maxPressure)` | |
Returns true if successful, if false check the logs | |
Device ID is arbitrary, but you will use it to send pen events so this is important if you register multiple pens | |
I think maxPressure is arbitrary; pressure values will be normalized internally from 0-1024. | |
For the flags, we automatically set the "Register" flag for you. | |
I think if you want to use pressure/tilt/rotation, you need to set those flags and you'll be expected to pass values for those. | |
The RDP X11 client only uses pressure, so it just passes `HasPressure` and sends pressure for every event | |
Register = 0x01, | |
EraserPressed = 0x02, | |
Press = 0x04, | |
Motion = 0x08, | |
Release = 0x10, | |
BarrelPressed = 0x20, | |
**HasPressure = 0x40,** | |
**HasRotation = 0x80,** | |
**HasTiltx = 0x100,** | |
**HasTilty = 0x200,** | |
IsInverted = 0x400 | |
`IsInverted` means the pen is upside down, i.e. you're using it as an eraser. You could register seperate pen and eraser, or | |
add the `IsInverted` flag dynamically (I think) | |
3. `public bool IsPen(int deviceId) => IsPen(this.Handle, deviceId)` - you can ask if the device ID is a registed pen. Maybe useful. | |
4. `public bool HandlePen(PenEventBuilder builder)` | |
This is how you send your pen events. I provided this `PenEventBuilder` because the C API is quite messy. Use it like this: | |
``` | |
// declare class level PenEventBuilder | |
private PenEventBuilder penBuilder = new PenEventBuilder() | |
const int deviceId = 1; // just for demo | |
``` | |
Everytime you want to send an event: | |
``` | |
NativeRdp.PenEventType.Flags flags = // provide the right flags (see below) | |
builder.New(flags, deviceId, x, y) | |
.WithPressure(25.3); // example setting pressure | |
this.Rdp.HandlePen(builder); // send the event | |
``` | |
EraserPressed // eraser button (top of pen) is pressed | |
Press = // pen is touching the digitizer | |
Motion = // pen is moving | |
Release = // pen is not touching the digitizer | |
BarrelPressed = // barrel button is pressed | |
IsInverted = // pen is upside down (eraser?) | |
I did a super simple test like this: | |
``` | |
private bool registered = false; | |
private PenEventBuilder builder = new PenEventBuilder(); | |
public void HandleMouseDown(int x, int y, MouseButton button, MouseButton buttons) | |
{ | |
if (!IsConnected) | |
{ | |
return; | |
} | |
if (!this.registered) | |
{ | |
this.Rdp.RegisterPen(0, 1, 1.0); | |
this.registered = true; | |
} | |
this.down = true; | |
builder.New(NativeRdp.PenEventType.Press, 1, x, y); | |
this.Rdp.HandlePen(builder); | |
} | |
public void HandleMouseMove(int x, int y, MouseButton buttons) | |
{ | |
if (!IsConnected) | |
{ | |
return; | |
} | |
if (!this.registered) | |
{ | |
return; | |
} | |
builder.New(NativeRdp.PenEventType.Motion, 1, x, y); | |
this.Rdp.HandlePen(builder); | |
} | |
public void HandleMouseUp(int x, int y, MouseButton button, MouseButton buttons) | |
{ | |
if (!IsConnected) | |
{ | |
return; | |
} | |
this.down = false; | |
builder.New(NativeRdp.PenEventType.Release, 1, x, y); | |
this.Rdp.HandlePen(builder); | |
} | |
``` | |
5. `public bool PenCancelAll()` | |
Not sure about this one. Cancels the hover state of all registered pens. Don't know why it's needed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment