「Xamarin.Mac/キーボードの入力をシミュレートする」の版間の差分
編集の要約なし |
|||
| 39行目: | 39行目: | ||
static void PostKeyWithModifiers(ushort keycode, CGEventFlags modifiers = 0) | static void PostKeyWithModifiers(ushort keycode, CGEventFlags modifiers = 0) | ||
{ | { | ||
var source = new CGEventSource(CGEventSourceStateID.CombinedSession); | using (var source = new CGEventSource(CGEventSourceStateID.CombinedSession)) | ||
using (var keydown = new CGEvent(source, keycode, keyDown: true)) | |||
using (var keyup = new CGEvent(source, keycode, keyDown: false)) | |||
{ | |||
keydown.Flags = modifiers; | |||
// 送信 | |||
CGEvent.Post(keydown, CGEventTapLocation.AnnotatedSession); | |||
CGEvent.Post(keyup , CGEventTapLocation.AnnotatedSession); | |||
} | |||
} | } | ||
} | } | ||