From b25cecf984251d9cbe087a6b7b70655632aa7377 Mon Sep 17 00:00:00 2001
From: vcaesar <vzvway@gmail.com>
Date: Wed, 17 Nov 2021 17:29:31 -0400
Subject: [PATCH] remove move scaled and drop some API keep one, add toggle
 micro sleep

---
 base/microsleep.h |  3 +--
 key/keypress_c.h  |  5 +++++
 mouse/mouse_c.h   |  3 ++-
 robotgo.go        | 23 +++++++++++++++--------
 4 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/base/microsleep.h b/base/microsleep.h
index bbb8a4f..777831c 100644
--- a/base/microsleep.h
+++ b/base/microsleep.h
@@ -20,8 +20,7 @@
  *
  * Pauses execution for the given amount of milliseconds.
  */
-H_INLINE void microsleep(double milliseconds)
-{
+H_INLINE void microsleep(double milliseconds) {
 #if defined(IS_WINDOWS)
 	Sleep((DWORD)milliseconds); /* (Unfortunately truncated to a 32-bit integer.) */
 #else
diff --git a/key/keypress_c.h b/key/keypress_c.h
index da63ae4..8fd0502 100644
--- a/key/keypress_c.h
+++ b/key/keypress_c.h
@@ -173,6 +173,7 @@ void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags){
 
 void tapKeyCode(MMKeyCode code, MMKeyFlags flags){
 	toggleKeyCode(code, true, flags);
+	microsleep(5.0);
 	toggleKeyCode(code, false, flags);
 }
 
@@ -224,6 +225,7 @@ void toggleKey(char c, const bool down, MMKeyFlags flags){
 
 void tapKey(char c, MMKeyFlags flags){
 	toggleKey(c, true, flags);
+	microsleep(5.0);
 	toggleKey(c, false, flags);
 }
 
@@ -289,6 +291,7 @@ void unicodeType(const unsigned value){
 		UniChar ch = (UniChar)value; // Convert to unsigned char
 
 		toggleUnicode(ch, true);
+		microsleep(5.0);
 		toggleUnicode(ch, false);
 	#elif defined(IS_WINDOWS)
 		INPUT input[2];
@@ -307,10 +310,12 @@ void unicodeType(const unsigned value){
   		SendInput(2, input, sizeof(INPUT));
 	#elif defined(USE_X11)
 		toggleUniKey(value, true);
+		microsleep(5.0);
 		toggleUniKey(value, false);	
 	#endif
 }
 
+// todo: removed
 void typeStringDelayed(const char *str, const unsigned cpm){
 	
 	/* Characters per second */
diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h
index 245f618..1b72e74 100644
--- a/mouse/mouse_c.h
+++ b/mouse/mouse_c.h
@@ -206,6 +206,7 @@ void toggleMouse(bool down, MMMouseButton button){
 
 void clickMouse(MMMouseButton button){
 	toggleMouse(true, button);
+	microsleep(5.0);
 	toggleMouse(false, button);
 }
 
@@ -309,7 +310,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
 	#endif
 }
 
-void scrollMouseXY(int x, int y){
+void scrollMouseXY(int x, int y) {
 	#if defined(IS_WINDOWS)
 		// Fix for #97,
 		// C89 needs variables declared on top of functions (mouseScrollInput)
diff --git a/robotgo.go b/robotgo.go
index eff9581..7d319e8 100644
--- a/robotgo.go
+++ b/robotgo.go
@@ -441,6 +441,7 @@ func CheckMouse(btn string) C.MMMouseButton {
 	return C.LEFT_BUTTON
 }
 
+// Deprecated:
 // MoveMouse move the mouse
 func MoveMouse(x, y int) {
 	Move(x, y)
@@ -452,10 +453,10 @@ func MoveMouse(x, y int) {
 // 	robotgo.MouseSleep = 100  // 100 millisecond
 // 	robotgo.Move(10, 10)
 func Move(x, y int) {
-	if runtime.GOOS == "windows" {
-		f := ScaleF()
-		x, y = Scaled0(x, f), Scaled0(y, f)
-	}
+	// if runtime.GOOS == "windows" {
+	// 	f := ScaleF()
+	// 	x, y = Scaled0(x, f), Scaled0(y, f)
+	// }
 
 	cx := C.int32_t(x)
 	cy := C.int32_t(y)
@@ -464,6 +465,7 @@ func Move(x, y int) {
 	MilliSleep(MouseSleep)
 }
 
+// Deprecated:
 // DragMouse drag the mouse to (x, y),
 // It's same with the DragSmooth() now
 func DragMouse(x, y int, args ...interface{}) {
@@ -474,6 +476,7 @@ func DragMouse(x, y int, args ...interface{}) {
 	Toggle("left", "up")
 }
 
+// Deprecated:
 // Drag drag the mouse to (x, y),
 // It's not valid now, use the DragSmooth()
 func Drag(x, y int, args ...string) {
@@ -500,6 +503,7 @@ func DragSmooth(x, y int, args ...interface{}) {
 	Toggle("left", "up")
 }
 
+// Deprecated:
 // 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 {
@@ -515,10 +519,10 @@ func MoveMouseSmooth(x, y int, args ...interface{}) bool {
 //	robotgo.MoveSmooth(10, 10)
 //	robotgo.MoveSmooth(10, 10, 1.0, 2.0)
 func MoveSmooth(x, y int, args ...interface{}) bool {
-	if runtime.GOOS == "windows" {
-		f := ScaleF()
-		x, y = Scaled0(x, f), Scaled0(y, f)
-	}
+	// if runtime.GOOS == "windows" {
+	// 	f := ScaleF()
+	// 	x, y = Scaled0(x, f), Scaled0(y, f)
+	// }
 
 	cx := C.int32_t(x)
 	cy := C.int32_t(y)
@@ -577,6 +581,7 @@ func GetMousePos() (int, int) {
 	return x, y
 }
 
+// Deprecated:
 // MouseClick click the mouse
 //
 // robotgo.MouseClick(button string, double bool)
@@ -646,6 +651,7 @@ func Toggle(key ...string) int {
 	return int(i)
 }
 
+// Deprecated:
 // MouseToggle toggle the mouse
 //
 // Examples:
@@ -666,6 +672,7 @@ func MouseToggle(togKey string, args ...interface{}) int {
 	return int(i)
 }
 
+// Deprecated:
 // ScrollMouse scroll the mouse to (x, "up")
 //
 // Examples: