SendIput with multiples INPUTs #235
Answered
by
ilopX
JillyTaboga
asked this question in
Q&A
Replies: 1 comment
-
// Copyright (c) 2020, Dart | Windows. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Demonstrates sending input to another window via SendInput()
// ignore_for_file: constant_identifier_names
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';
const VK_SHIFT = 0x10;
const VK_D = 0x44;
void main() {
runNotepad();
sendKeyDown(VK_SHIFT);
sendKeyDown(VK_D);
sendKeyUp(VK_D);
sendKeyUp(VK_SHIFT);
sendUnicode("art is awesome €");
}
void runNotepad() {
print('Switching to Notepad and going to sleep for a second.');
ShellExecute(0, TEXT('open'), TEXT('notepad.exe'), nullptr, nullptr, SW_SHOW);
Sleep(1000);
}
void sendKeyDown(int virtualKey) {
final kbd = calloc<INPUT>();
kbd.ref.type = INPUT_KEYBOARD;
kbd.ref.ki.wVk = virtualKey;
final result = SendInput(1, kbd, sizeOf<INPUT>());
if (result != TRUE) print('Error: ${GetLastError()}');
free(kbd);
}
void sendKeyUp(int virtualKey) {
final kbd = calloc<INPUT>();
kbd.ref.type = INPUT_KEYBOARD;
kbd.ref.ki.wVk = virtualKey;
kbd.ref.ki.dwFlags = KEYEVENTF_KEYUP;
final result = SendInput(1, kbd, sizeOf<INPUT>());
if (result != TRUE) print('Error: ${GetLastError()}');
free(kbd);
}
void sendUnicode(String text) {
for (final code in text.codeUnits) {
final kbd = calloc<INPUT>();
kbd.ref.type = INPUT_KEYBOARD;
kbd.ref.ki.wVk = 0;
kbd.ref.ki.wScan = code;
kbd.ref.ki.dwFlags = KEYEVENTF_UNICODE;
final result = SendInput(1, kbd, sizeOf<INPUT>());
if (result != TRUE) print('Error: ${GetLastError()}');
free(kbd);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JillyTaboga
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The SendInput receive a array of INPUTs, but the example just show cases with one INPUT could anyone show a example with a multi INPUTs, like shift+A?
Beta Was this translation helpful? Give feedback.
All reactions