Compare commits

...

11 Commits

Author SHA1 Message Date
jonasbark
dda2135129 Merge pull request #30 from jonasbark/copilot/fix-26
Implement window-focused key simulation for Windows applications
2025-07-04 08:51:42 +02:00
copilot-swe-agent[bot]
bc2831c17e Update version to 2.1.0 and add changelog entry for automatic window focusing feature
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 15:00:12 +00:00
copilot-swe-agent[bot]
310313c3b2 Add check to avoid focusing window if already in foreground
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 14:56:11 +00:00
copilot-swe-agent[bot]
2122568461 Remove documentation and utility files as requested, keep automatic window focusing in Windows C++ plugin
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 14:23:43 +00:00
copilot-swe-agent[bot]
144fd5b740 Remove Dart API changes and implement automatic window focusing in Windows SimulateKeyPress method
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 14:13:14 +00:00
copilot-swe-agent[bot]
5f7a1a8203 Complete window-focused key simulation implementation with utilities and README update
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 14:02:59 +00:00
copilot-swe-agent[bot]
258b396444 Add documentation and testing tools for window-focused key simulation feature
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 14:01:10 +00:00
copilot-swe-agent[bot]
5861533793 Improve window-focused key simulation with better error handling and SendInput fallback
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 13:59:47 +00:00
copilot-swe-agent[bot]
3106bd09e8 Implement window-focused key simulation for Windows applications
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-07-03 13:53:30 +00:00
copilot-swe-agent[bot]
a3475a02d2 Initial plan 2025-07-03 13:42:04 +00:00
Jonas Bark
fb1a1f35ad you can now assign Escape and arrow down key to your custom keymap (fixes #18) 2025-05-04 10:46:00 +02:00
6 changed files with 100 additions and 2 deletions

View File

@@ -1,3 +1,9 @@
### 2.1.0 (2025-07-03)
- Windows: automatically focus compatible training apps (MyWhoosh, IndieVelo, Biketerra) when sending keystrokes, enabling seamless multi-window usage
### 2.0.9 (2025-05-04)
- you can now assign Escape and arrow down key to your custom keymap (#18)
### 2.0.8 (2025-05-02)
- only use the light theme for the app
- more troubleshooting information

View File

@@ -2,6 +2,8 @@
// This must be included before many other Windows headers.
#include <windows.h>
#include <psapi.h>
#include <string.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
@@ -54,6 +56,27 @@ void KeypressSimulatorWindowsPlugin::SimulateKeyPress(
modifiers.push_back(key_modifier);
}
// List of compatible training apps to look for
std::vector<std::string> compatibleApps = {
"MyWhooshHD.exe",
"indieVelo.exe",
"biketerra.exe"
};
// Try to find and focus a compatible app
HWND targetWindow = NULL;
for (const std::string& processName : compatibleApps) {
targetWindow = FindTargetWindow(processName, "");
if (targetWindow != NULL) {
// Only focus the window if it's not already in the foreground
if (GetForegroundWindow() != targetWindow) {
SetForegroundWindow(targetWindow);
Sleep(50); // Brief delay to ensure window is focused
}
break;
}
}
INPUT input[6];
for (int32_t i = 0; i < modifiers.size(); i++) {
@@ -121,6 +144,73 @@ void KeypressSimulatorWindowsPlugin::SimulateMouseClick(
result->Success(flutter::EncodableValue(true));
}
// Helper function to find window by process name or window title
struct FindWindowData {
std::string targetProcessName;
std::string targetWindowTitle;
HWND foundWindow;
};
BOOL CALLBACK EnumWindowsCallback(HWND hwnd, LPARAM lParam) {
FindWindowData* data = reinterpret_cast<FindWindowData*>(lParam);
// Check if window is visible and not minimized
if (!IsWindowVisible(hwnd) || IsIconic(hwnd)) {
return TRUE; // Continue enumeration
}
// Get window title
char windowTitle[256];
GetWindowTextA(hwnd, windowTitle, sizeof(windowTitle));
// Get process name
DWORD processId;
GetWindowThreadProcessId(hwnd, &processId);
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
char processName[MAX_PATH];
if (hProcess) {
DWORD size = sizeof(processName);
if (QueryFullProcessImageNameA(hProcess, 0, processName, &size)) {
// Extract just the filename from the full path
char* filename = strrchr(processName, '\\');
if (filename) {
filename++; // Skip the backslash
} else {
filename = processName;
}
// Check if this matches our target
if (!data->targetProcessName.empty() &&
_stricmp(filename, data->targetProcessName.c_str()) == 0) {
data->foundWindow = hwnd;
return FALSE; // Stop enumeration
}
}
CloseHandle(hProcess);
}
// Check window title if process name didn't match
if (!data->targetWindowTitle.empty() &&
_stricmp(windowTitle, data->targetWindowTitle.c_str()) == 0) {
data->foundWindow = hwnd;
return FALSE; // Stop enumeration
}
return TRUE; // Continue enumeration
}
HWND FindTargetWindow(const std::string& processName, const std::string& windowTitle) {
FindWindowData data;
data.targetProcessName = processName;
data.targetWindowTitle = windowTitle;
data.foundWindow = NULL;
EnumWindows(EnumWindowsCallback, reinterpret_cast<LPARAM>(&data));
return data.foundWindow;
}
void KeypressSimulatorWindowsPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {

View File

@@ -30,6 +30,8 @@ class KeypressSimulatorWindowsPlugin : public flutter::Plugin {
const flutter::MethodCall<flutter::EncodableValue>& method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
// Called when a method is called on this plugin's channel from Dart.
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& method_call,

View File

@@ -125,6 +125,7 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
onTap: () async {
await showDialog<void>(
context: context,
barrierDismissible: false, // enable Escape key
builder:
(c) =>
HotKeyListenerDialog(customApp: actionHandler.supportedApp! as CustomApp, keyPair: keyPair),

View File

@@ -67,7 +67,6 @@ class _HotKeyListenerState extends State<HotKeyListenerDialog> {
setState(() {
if (event is KeyDownEvent) {
_pressedKey = event;
} else if (event is KeyUpEvent) {
widget.customApp.setKey(
_pressedButton!,
physicalKey: _pressedKey!.physicalKey,

View File

@@ -1,7 +1,7 @@
name: swift_control
description: "SwiftControl - Control your virtual riding"
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 2.0.8+0
version: 2.1.0+0
environment:
sdk: ^3.7.0