Skip to content

Commit

Permalink
Update: used NotPid option args and move Deprecated func to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Jan 20, 2023
1 parent f830c8e commit df1617d
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 119 deletions.
13 changes: 2 additions & 11 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"unsafe"

"github.com/go-vgo/robotgo/clipboard"
"github.com/vcaesar/tt"
)

// Defining a bunch of constants.
Expand Down Expand Up @@ -723,22 +722,14 @@ func PasteStr(str string) error {
}

// TypeStrDelay type string with delayed
// And you can use robotgo.KeySleep = 100 to delayed not this function
func TypeStrDelay(str string, delay int) {
TypeStr(str)
MilliSleep(delay)
}

// Deprecated: use the TypeStr(),
//
// # TypeStringDelayed type string delayed, Wno-deprecated
//
// This function will be removed in version v1.0.0
func TypeStringDelayed(str string, delay int) {
tt.Drop("TypeStringDelayed", "TypeStrDelay")
TypeStrDelay(str, delay)
}

// SetDelay sets the key and mouse delay
// robotgo.SetDelay(100) option the robotgo.KeySleep and robotgo.MouseSleep = d
func SetDelay(d ...int) {
v := 10
if len(d) > 0 {
Expand Down
103 changes: 11 additions & 92 deletions robotgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ func CaptureScreen(args ...int) CBitmap {
if NotPid || len(args) > 5 {
isPid = 1
}

bit := C.capture_screen(x, y, w, h, C.int32_t(displayId), C.int8_t(isPid))
return CBitmap(bit)
}
Expand Down Expand Up @@ -444,45 +445,6 @@ func ScaleX() int {
return int(C.scaleX())
}

// Deprecated: use the ScaledF(),
//
// Scale get the screen scale (only windows old), drop
func Scale() int {
dpi := map[int]int{
0: 100,
// DPI Scaling Level
96: 100,
120: 125,
144: 150,
168: 175,
192: 200,
216: 225,
// Custom DPI
240: 250,
288: 300,
384: 400,
480: 500,
}

x := ScaleX()
return dpi[x]
}

// Deprecated: use the ScaledF(),
//
// Scale0 return ScaleX() / 0.96, drop
func Scale0() int {
return int(float64(ScaleX()) / 0.96)
}

// Deprecated: use the ScaledF(),
//
// Mul mul the scale, drop
func Mul(x int) int {
s := Scale()
return x * s / 100
}

/*
.___ ___. ______ __ __ _______. _______
| \/ | / __ \ | | | | / || ____|
Expand Down Expand Up @@ -512,13 +474,6 @@ func CheckMouse(btn string) C.MMMouseButton {
return C.LEFT_BUTTON
}

// Deprecated: use the Move(),
//
// MoveMouse move the mouse
func MoveMouse(x, y int) {
Move(x, y)
}

// Move move the mouse to (x, y)
//
// Examples:
Expand All @@ -538,18 +493,6 @@ func Move(x, y int) {
MilliSleep(MouseSleep)
}

// Deprecated: use the DragSmooth(),
//
// DragMouse drag the mouse to (x, y),
// It's same with the DragSmooth() now
func DragMouse(x, y int, args ...interface{}) {
Toggle("left")
MilliSleep(50)
// Drag(x, y, args...)
MoveSmooth(x, y, args...)
Toggle("left", "up")
}

// Deprecated: use the DragSmooth(),
//
// Drag drag the mouse to (x, y),
Expand Down Expand Up @@ -579,14 +522,6 @@ func DragSmooth(x, y int, args ...interface{}) {
Toggle("left", "up")
}

// Deprecated: use the MoveSmooth(),
//
// MoveMouseSmooth move the mouse smooth,
// moves mouse to x, y human like, with the mouse button up.
func MoveMouseSmooth(x, y int, args ...interface{}) bool {
return MoveSmooth(x, y, args...)
}

// MoveSmooth move the mouse smooth,
// moves mouse to x, y human like, with the mouse button up.
//
Expand Down Expand Up @@ -649,13 +584,6 @@ func MoveSmoothRelative(x, y int, args ...interface{}) {
MoveSmooth(mx, my, args...)
}

// Deprecated: use the function Location()
//
// GetMousePos get the mouse's position return x, y
func GetMousePos() (int, int) {
return Location()
}

// Location get the mouse location position return x, y
func Location() (int, int) {
pos := C.location()
Expand All @@ -665,15 +593,6 @@ func Location() (int, int) {
return x, y
}

// Deprecated: use the Click(),
//
// # MouseClick click the mouse
//
// robotgo.MouseClick(button string, double bool)
func MouseClick(args ...interface{}) {
Click(args...)
}

// Click click the mouse button
//
// robotgo.Click(button string, double bool)
Expand Down Expand Up @@ -938,8 +857,8 @@ func MinWindow(pid int, args ...interface{}) {
if len(args) > 0 {
state = args[0].(bool)
}
if len(args) > 1 {
isPid = args[1].(int)
if len(args) > 1 || NotPid {
isPid = 1
}

C.min_window(C.uintptr(pid), C.bool(state), C.int8_t(isPid))
Expand All @@ -955,8 +874,8 @@ func MaxWindow(pid int, args ...interface{}) {
if len(args) > 0 {
state = args[0].(bool)
}
if len(args) > 1 {
isPid = args[1].(int)
if len(args) > 1 || NotPid {
isPid = 1
}

C.max_window(C.uintptr(pid), C.bool(state), C.int8_t(isPid))
Expand All @@ -973,8 +892,8 @@ func CloseWindow(args ...int) {
if len(args) > 0 {
pid = args[0]
}
if len(args) > 1 {
isPid = args[1]
if len(args) > 1 || NotPid {
isPid = 1
}

C.close_window_by_PId(C.uintptr(pid), C.int8_t(isPid))
Expand All @@ -989,8 +908,8 @@ func SetHandle(hwnd int) {
// SetHandlePid set the window handle by pid
func SetHandlePid(pid int, args ...int) {
var isPid int
if len(args) > 0 {
isPid = args[0]
if len(args) > 0 || NotPid {
isPid = 1
}

C.set_handle_pid_mData(C.uintptr(pid), C.int8_t(isPid))
Expand All @@ -999,8 +918,8 @@ func SetHandlePid(pid int, args ...int) {
// GetHandPid get handle mdata by pid
func GetHandPid(pid int, args ...int) C.MData {
var isPid int
if len(args) > 0 {
isPid = args[0]
if len(args) > 0 || NotPid {
isPid = 1
}

return C.set_handle_pid(C.uintptr(pid), C.int8_t(isPid))
Expand Down
95 changes: 95 additions & 0 deletions robotgo_fn_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package robotgo

import "github.com/vcaesar/tt"

// Deprecated: use the Move(),
//
// MoveMouse move the mouse
func MoveMouse(x, y int) {
Move(x, y)
}

// Deprecated: use the DragSmooth(),
//
// DragMouse drag the mouse to (x, y),
// It's same with the DragSmooth() now
func DragMouse(x, y int, args ...interface{}) {
Toggle("left")
MilliSleep(50)
// Drag(x, y, args...)
MoveSmooth(x, y, args...)
Toggle("left", "up")
}

// Deprecated: use the MoveSmooth(),
//
// MoveMouseSmooth move the mouse smooth,
// moves mouse to x, y human like, with the mouse button up.
func MoveMouseSmooth(x, y int, args ...interface{}) bool {
return MoveSmooth(x, y, args...)
}

// Deprecated: use the function Location()
//
// GetMousePos get the mouse's position return x, y
func GetMousePos() (int, int) {
return Location()
}

// Deprecated: use the Click(),
//
// # MouseClick click the mouse
//
// robotgo.MouseClick(button string, double bool)
func MouseClick(args ...interface{}) {
Click(args...)
}

// Deprecated: use the TypeStr(),
//
// # TypeStringDelayed type string delayed, Wno-deprecated
//
// This function will be removed in version v1.0.0
func TypeStringDelayed(str string, delay int) {
tt.Drop("TypeStringDelayed", "TypeStrDelay")
TypeStrDelay(str, delay)
}

// Deprecated: use the ScaledF(),
//
// Scale get the screen scale (only windows old), drop
func Scale() int {
dpi := map[int]int{
0: 100,
// DPI Scaling Level
96: 100,
120: 125,
144: 150,
168: 175,
192: 200,
216: 225,
// Custom DPI
240: 250,
288: 300,
384: 400,
480: 500,
}

x := ScaleX()
return dpi[x]
}

// Deprecated: use the ScaledF(),
//
// Scale0 return ScaleX() / 0.96, drop
func Scale0() int {
return int(float64(ScaleX()) / 0.96)
}

// Deprecated: use the ScaledF(),
//
// Mul mul the scale, drop
func Mul(x int) int {
s := Scale()
return x * s / 100
}
16 changes: 8 additions & 8 deletions robotgo_mac_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package robotgo
// GetBounds get the window bounds
func GetBounds(pid int, args ...int) (int, int, int, int) {
var isPid int
if len(args) > 0 {
isPid = args[0]
if len(args) > 0 || NotPid {
isPid = 1
}

return internalGetBounds(pid, isPid)
Expand All @@ -26,8 +26,8 @@ func GetBounds(pid int, args ...int) (int, int, int, int) {
// GetClient get the window client bounds
func GetClient(pid int, args ...int) (int, int, int, int) {
var isPid int
if len(args) > 0 {
isPid = args[0]
if len(args) > 0 || NotPid {
isPid = 1
}

return internalGetClient(pid, isPid)
Expand All @@ -36,8 +36,8 @@ func GetClient(pid int, args ...int) (int, int, int, int) {
// internalGetTitle get the window title
func internalGetTitle(pid int, args ...int) string {
var isPid int
if len(args) > 0 {
isPid = args[0]
if len(args) > 0 || NotPid {
isPid = 1
}
gtitle := cgetTitle(pid, isPid)

Expand All @@ -54,8 +54,8 @@ func internalGetTitle(pid int, args ...int) string {
// robotgo.ActivePid(ids[0])
func ActivePid(pid int, args ...int) error {
var isPid int
if len(args) > 0 {
isPid = args[0]
if len(args) > 0 || NotPid {
isPid = 1
}

internalActive(pid, isPid)
Expand Down
Loading

0 comments on commit df1617d

Please sign in to comment.