-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability for emulator to emulate keyboard events for ring button e…
…mulation
- Loading branch information
1 parent
b73e88f
commit 48cdfd0
Showing
13 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace WpfMaiTouchEmulator; | ||
public partial class RingButtonEmulator | ||
{ | ||
|
||
[DllImport("user32.dll")] | ||
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); | ||
|
||
private static readonly IDictionary<TouchValue, byte> touchRingMapping = new Dictionary<TouchValue, byte>() | ||
{ | ||
{ TouchValue.A1, 0x57 }, // W | ||
{ TouchValue.A2, 0x45 }, // E | ||
{ TouchValue.A3, 0x44 }, // D | ||
{ TouchValue.A4, 0x43 }, // C | ||
{ TouchValue.A5, 0x58 }, // X | ||
{ TouchValue.A6, 0x5A }, // Z | ||
{ TouchValue.A7, 0x41 }, // A | ||
{ TouchValue.A8, 0x51 }, // Q | ||
}; | ||
private const uint KEYEVENTF_KEYUP = 0x0002; | ||
|
||
public static bool HasRingButtonMapping(TouchValue touchValue) | ||
{ | ||
return touchRingMapping.ContainsKey(touchValue); | ||
} | ||
|
||
public static void PressButton(TouchValue touchValue) | ||
{ | ||
if (touchRingMapping.TryGetValue(touchValue, out var vk)) | ||
{ | ||
keybd_event(vk, 0, 0, UIntPtr.Zero); | ||
} | ||
} | ||
|
||
public static void ReleaseButton(TouchValue touchValue) | ||
{ | ||
if (touchRingMapping.TryGetValue(touchValue, out var vk)) | ||
{ | ||
keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero); | ||
} | ||
} | ||
|
||
public static void ReleaseAllButtons() | ||
{ | ||
foreach (var vk in touchRingMapping.Values) | ||
{ | ||
keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero); | ||
} | ||
} | ||
} |
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