mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
Update: Optimize window hand code
This commit is contained in:
parent
f911550742
commit
6313e52156
@ -1,6 +1,16 @@
|
|||||||
#include "keypress.h"
|
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
#include "../base/deadbeef_rand_c.h"
|
#include "../base/deadbeef_rand_c.h"
|
||||||
#include "../base/microsleep.h"
|
#include "../base/microsleep.h"
|
||||||
|
#include "keypress.h"
|
||||||
#include "keycode_c.h"
|
#include "keycode_c.h"
|
||||||
|
|
||||||
#include <ctype.h> /* For isupper() */
|
#include <ctype.h> /* For isupper() */
|
||||||
@ -17,6 +27,14 @@
|
|||||||
#if defined(IS_WINDOWS)
|
#if defined(IS_WINDOWS)
|
||||||
HWND GetHwndByPid(DWORD dwProcessId);
|
HWND GetHwndByPid(DWORD dwProcessId);
|
||||||
|
|
||||||
|
HWND getHwnd(uintptr pid, int8_t isPid) {
|
||||||
|
HWND hwnd = (HWND) pid;
|
||||||
|
if (isPid == 0) {
|
||||||
|
hwnd = GetHwndByPid(pid);
|
||||||
|
}
|
||||||
|
return hwnd;
|
||||||
|
}
|
||||||
|
|
||||||
void WIN32_KEY_EVENT_WAIT(MMKeyCode key, DWORD flags, uintptr pid) {
|
void WIN32_KEY_EVENT_WAIT(MMKeyCode key, DWORD flags, uintptr pid) {
|
||||||
win32KeyEvent(key, flags, pid, 0);
|
win32KeyEvent(key, flags, pid, 0);
|
||||||
Sleep(DEADBEEF_RANDRANGE(0, 1));
|
Sleep(DEADBEEF_RANDRANGE(0, 1));
|
||||||
@ -115,10 +133,8 @@ void win32KeyEvent(int key, MMKeyFlags flags, uintptr pid, int8_t isPid) {
|
|||||||
|
|
||||||
// todo: test this
|
// todo: test this
|
||||||
if (pid != 0) {
|
if (pid != 0) {
|
||||||
HWND hwnd = (HWND) pid;
|
HWND hwnd = getHwnd(pid, isPid);
|
||||||
if (isPid == 0) {
|
|
||||||
hwnd = GetHwndByPid(pid);
|
|
||||||
}
|
|
||||||
int down = (flags == 0 ? WM_KEYDOWN : WM_KEYUP);
|
int down = (flags == 0 ? WM_KEYDOWN : WM_KEYUP);
|
||||||
// SendMessage(hwnd, down, key, 0);
|
// SendMessage(hwnd, down, key, 0);
|
||||||
PostMessageW(hwnd, down, key, 0);
|
PostMessageW(hwnd, down, key, 0);
|
||||||
@ -316,10 +332,7 @@ void unicodeType(const unsigned value, uintptr pid, int8_t isPid){
|
|||||||
toggleUnicode(ch, false, pid);
|
toggleUnicode(ch, false, pid);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
if (pid != 0) {
|
if (pid != 0) {
|
||||||
HWND hwnd = (HWND) pid;
|
HWND hwnd = getHwnd(pid, isPid);
|
||||||
if (isPid == 0) {
|
|
||||||
hwnd = GetHwndByPid(pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendMessage(hwnd, down, value, 0);
|
// SendMessage(hwnd, down, value, 0);
|
||||||
PostMessageW(hwnd, WM_CHAR, value, 0);
|
PostMessageW(hwnd, WM_CHAR, value, 0);
|
||||||
|
@ -18,6 +18,7 @@ int showAlert(const char *title, const char *msg,
|
|||||||
CFStringRef defaultButtonTitle = CFStringCreateWithUTF8String(defaultButton);
|
CFStringRef defaultButtonTitle = CFStringCreateWithUTF8String(defaultButton);
|
||||||
CFStringRef cancelButtonTitle = CFStringCreateWithUTF8String(cancelButton);
|
CFStringRef cancelButtonTitle = CFStringCreateWithUTF8String(cancelButton);
|
||||||
CFOptionFlags responseFlags;
|
CFOptionFlags responseFlags;
|
||||||
|
|
||||||
SInt32 err = CFUserNotificationDisplayAlert(
|
SInt32 err = CFUserNotificationDisplayAlert(
|
||||||
0.0, kCFUserNotificationNoteAlertLevel, NULL, NULL, NULL, alertHeader, alertMessage,
|
0.0, kCFUserNotificationNoteAlertLevel, NULL, NULL, NULL, alertHeader, alertMessage,
|
||||||
defaultButtonTitle, cancelButtonTitle, NULL, &responseFlags);
|
defaultButtonTitle, cancelButtonTitle, NULL, &responseFlags);
|
||||||
|
@ -23,12 +23,8 @@ void min_window(uintptr pid, bool state, int8_t isPid){
|
|||||||
XDismissErrors();
|
XDismissErrors();
|
||||||
// SetState((Window)pid, STATE_MINIMIZE, state);
|
// SetState((Window)pid, STATE_MINIMIZE, state);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
if (isPid == 0) {
|
HWND hwnd = getHwnd(pid, isPid);
|
||||||
HWND hwnd = GetHwndByPid(pid);
|
win_min(hwnd, state);
|
||||||
win_min(hwnd, state);
|
|
||||||
} else {
|
|
||||||
win_min((HWND)pid, state);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,12 +36,8 @@ void max_window(uintptr pid, bool state, int8_t isPid){
|
|||||||
// SetState((Window)pid, STATE_MINIMIZE, false);
|
// SetState((Window)pid, STATE_MINIMIZE, false);
|
||||||
// SetState((Window)pid, STATE_MAXIMIZE, state);
|
// SetState((Window)pid, STATE_MAXIMIZE, state);
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
if (isPid == 0) {
|
HWND hwnd = getHwnd(pid, isPid);
|
||||||
HWND hwnd = GetHwndByPid(pid);
|
win_max(hwnd, state);
|
||||||
win_max(hwnd, state);
|
|
||||||
} else {
|
|
||||||
win_max((HWND)pid, state);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +267,8 @@ typedef struct _Bounds Bounds;
|
|||||||
|
|
||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
HWND getHwnd(uintptr pid, int8_t isPid);
|
||||||
|
|
||||||
void win_min(HWND hwnd, bool state){
|
void win_min(HWND hwnd, bool state){
|
||||||
if (state) {
|
if (state) {
|
||||||
ShowWindow(hwnd, SW_MINIMIZE);
|
ShowWindow(hwnd, SW_MINIMIZE);
|
||||||
|
@ -128,12 +128,7 @@ Bounds get_bounds(uintptr pid, int8_t isPid){
|
|||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
HWND hwnd;
|
HWND hwnd = getHwnd(pid, isPid);
|
||||||
if (isPid == 0) {
|
|
||||||
hwnd= GetHwndByPid(pid);
|
|
||||||
} else {
|
|
||||||
hwnd = (HWND)pid;
|
|
||||||
}
|
|
||||||
|
|
||||||
RECT rect = { 0 };
|
RECT rect = { 0 };
|
||||||
GetWindowRect(hwnd, &rect);
|
GetWindowRect(hwnd, &rect);
|
||||||
@ -193,12 +188,7 @@ Bounds get_client(uintptr pid, int8_t isPid) {
|
|||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
HWND hwnd;
|
HWND hwnd = getHwnd(pid, isPid);
|
||||||
if (isPid == 0) {
|
|
||||||
hwnd = GetHwndByPid(pid);
|
|
||||||
} else {
|
|
||||||
hwnd = (HWND)pid;
|
|
||||||
}
|
|
||||||
|
|
||||||
RECT rect = { 0 };
|
RECT rect = { 0 };
|
||||||
GetClientRect(hwnd, &rect);
|
GetClientRect(hwnd, &rect);
|
||||||
|
@ -59,11 +59,7 @@ MData set_handle_pid(uintptr pid, int8_t isPid){
|
|||||||
win.XWin = (Window)pid; // Handle to an X11 window
|
win.XWin = (Window)pid; // Handle to an X11 window
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
// win.HWnd = (HWND)pid; // Handle to a window HWND
|
// win.HWnd = (HWND)pid; // Handle to a window HWND
|
||||||
if (isPid == 0) {
|
win.HWnd = getHwnd(pid, isPid);
|
||||||
win.HWnd = GetHwndByPid(pid);
|
|
||||||
} else {
|
|
||||||
win.HWnd = (HWND)pid;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
|
Loading…
Reference in New Issue
Block a user