From b1ad7db6bead8499aa3c275be7557f8077e69ed1 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Tue, 17 Sep 2024 13:32:46 -0700 Subject: [PATCH 1/2] Add: export Handle data and add more window handle function #683 --- robotgo.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/robotgo.go b/robotgo.go index 5ac065a6..f0647fca 100644 --- a/robotgo.go +++ b/robotgo.go @@ -90,6 +90,8 @@ type ( CHex C.MMRGBHex // CBitmap define CBitmap as C.MMBitmapRef type CBitmap C.MMBitmapRef + // Handle define window Handle as C.MData type + Handle C.MData ) // Bitmap define the go Bitmap struct @@ -875,12 +877,22 @@ func IsValid() bool { } // SetActive set the window active -func SetActive(win C.MData) { +func SetActive(win Handle) { + SetActiveC(C.MData(win)) +} + +// SetActiveC set the window active +func SetActiveC(win C.MData) { C.set_active(win) } // GetActive get the active window -func GetActive() C.MData { +func GetActive() Handle { + return Handle(GetActiveC()) +} + +// GetActive get the active window +func GetActiveC() C.MData { mdata := C.get_active() // fmt.Println("active----", mdata) return mdata @@ -954,8 +966,29 @@ func SetHandlePid(pid int, args ...int) { C.set_handle_pid_mData(C.uintptr(pid), C.int8_t(isPid)) } +// GetHandById get handle mdata by id +func GetHandById(id int, args ...int) Handle { + isPid := 1 + if len(args) > 0 { + isPid = args[0] + } + return GetHandByPid(id, isPid) +} + +// GetHandByPid get handle mdata by pid +func GetHandByPid(pid int, args ...int) Handle { + return Handle(GetHandByPidC(pid, args...)) +} + +// Deprecated: use the GetHandByPid(), +// // GetHandPid get handle mdata by pid -func GetHandPid(pid int, args ...int) C.MData { +func GetHandPid(pid int, args ...int) Handle { + return GetHandByPid(pid, args...) +} + +// GetHandByPidC get handle mdata by pid +func GetHandByPidC(pid int, args ...int) C.MData { var isPid int if len(args) > 0 || NotPid { isPid = 1 From c48e3d072c0e8698ec5adf91a4559795a3c2102c Mon Sep 17 00:00:00 2001 From: vcaesar Date: Tue, 17 Sep 2024 13:38:38 -0700 Subject: [PATCH 2/2] Update: Fixed godoc --- robotgo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robotgo.go b/robotgo.go index f0647fca..4057b28e 100644 --- a/robotgo.go +++ b/robotgo.go @@ -891,7 +891,7 @@ func GetActive() Handle { return Handle(GetActiveC()) } -// GetActive get the active window +// GetActiveC get the active window func GetActiveC() C.MData { mdata := C.get_active() // fmt.Println("active----", mdata)