diff --git a/mousecolor.py b/mousecolor.py new file mode 100644 index 0000000..df0aec9 --- /dev/null +++ b/mousecolor.py @@ -0,0 +1,28 @@ +import pyautogui +import time +from PIL import Image + +def find_color_in_image(target_color, image): + width, height = image.size + for x in range(width): + for y in range(height): + if image.getpixel((x, y))[:3] == target_color: + return x, y + return None, None + +print("Move the mouse to the start position. Waiting for 10 seconds...") +time.sleep(10) + +mouse_x, mouse_y = pyautogui.position() +initial_color = pyautogui.pixel(mouse_x, mouse_y) +print(f"Initial Color at ({mouse_x}, {mouse_y}): {initial_color}") + +print("Taking a screenshot for color search...") +screenshot = pyautogui.screenshot() + +found_x, found_y = find_color_in_image(initial_color, screenshot) +if found_x is not None: + print(f"Color found at ({found_x}, {found_y}). Moving mouse to this position.") + pyautogui.moveTo(found_x, found_y) +else: + print("Color not found on the screen.") diff --git a/trade2.py b/trade2.py deleted file mode 100644 index 42b49a4..0000000 --- a/trade2.py +++ /dev/null @@ -1,64 +0,0 @@ -import subprocess -import time - -def right_click(x, y): - move_mouse(x, y) - print("Performing right click.") - subprocess.run(['xdotool', 'click', '3']) # Right-click - -def drag_slider(start_x, start_y, end_x, end_y): - print("Dragging slider.") - move_mouse(start_x, start_y) - subprocess.run(['xdotool', 'mousedown', '1']) # Left mouse button down - move_mouse(end_x, end_y) - subprocess.run(['xdotool', 'mouseup', '1']) # Left mouse button up - -def click(x, y): - move_mouse(x, y) - print("Performing left click.") - subprocess.run(['xdotool', 'click', '1']) # Left-click - -def shift_click(x, y): - print("Performing shift click.") - move_mouse(x, y) - subprocess.run(['xdotool', 'keydown', 'shift', 'click', '1', 'keyup', 'shift']) # Shift-click - -def move_mouse(x, y): - subprocess.run(['xdotool', 'mousemove', str(x), str(y)]) - -def focus_minecraft_window(): - print("Focusing Minecraft window...") - # Replace 'MinecraftWindowName' with the actual window name - subprocess.run(['xdotool', 'search', '--name', 'MinecraftWindowName', 'windowactivate', '--sync']) - time.sleep(2) - print("Pressing Esc...") - subprocess.run(['xdotool', 'key', 'Escape']) - time.sleep(2) - -# Initial setup -focus_minecraft_window() - -# Perform actions -right_click(2725, 1203) -time.sleep(3) - -drag_slider(2600, 1399, 2600, 1408) -time.sleep(3) - -click(2450, 1408) -time.sleep(3) - -shift_click(2994, 1105) -time.sleep(3) - -# Press 'Esc' key to possibly exit a menu or screen -print("Pressing 'Esc' key.") -subprocess.run(['xdotool', 'key', 'Escape']) -time.sleep(3) - -# Press and hold 'D' key for a duration to simulate a step -print("Holding 'D' key for a step.") -subprocess.run(['xdotool', 'keydown', 'd']) -time.sleep(0.4) # Hold 'D' for 0.4 second; adjust this duration as needed -subprocess.run(['xdotool', 'keyup', 'd']) -time.sleep(10) # Wait after the step diff --git a/trader.py b/trader.py index 42b49a4..5e44a9b 100644 --- a/trader.py +++ b/trader.py @@ -1,5 +1,7 @@ import subprocess import time +import pyautogui +from PIL import Image def right_click(x, y): move_mouse(x, y) @@ -26,6 +28,14 @@ def shift_click(x, y): def move_mouse(x, y): subprocess.run(['xdotool', 'mousemove', str(x), str(y)]) +def find_color_in_image(target_color, image): + width, height = image.size + for x in range(width): + for y in range(height): + if image.getpixel((x, y))[:3] == target_color: + return x, y + return None, None + def focus_minecraft_window(): print("Focusing Minecraft window...") # Replace 'MinecraftWindowName' with the actual window name @@ -35,30 +45,38 @@ def focus_minecraft_window(): subprocess.run(['xdotool', 'key', 'Escape']) time.sleep(2) +def trade_actions(): + right_click(2725, 1203) + time.sleep(3) + drag_slider(2600, 1399, 2600, 1408) + time.sleep(3) + + # Find the color and click + print("Taking a screenshot for color search...") + screenshot = pyautogui.screenshot() + target_color = (222, 227, 114) # The color to search for + found_x, found_y = find_color_in_image(target_color, screenshot) + if found_x is not None: + print(f"Color found at ({found_x}, {found_y}). Clicking at this position.") + click(found_x, found_y) + else: + print("Color not found on the screen.") + time.sleep(3) + + shift_click(2994, 1105) + time.sleep(3) + print("Pressing 'Esc' key.") + subprocess.run(['xdotool', 'key', 'Escape']) + time.sleep(3) + print("Holding 'D' key for a step.") + subprocess.run(['xdotool', 'keydown', 'd']) + time.sleep(0.45) # Hold 'D' for 0.45 seconds + subprocess.run(['xdotool', 'keyup', 'd']) + time.sleep(3) + # Initial setup focus_minecraft_window() -# Perform actions -right_click(2725, 1203) -time.sleep(3) - -drag_slider(2600, 1399, 2600, 1408) -time.sleep(3) - -click(2450, 1408) -time.sleep(3) - -shift_click(2994, 1105) -time.sleep(3) - -# Press 'Esc' key to possibly exit a menu or screen -print("Pressing 'Esc' key.") -subprocess.run(['xdotool', 'key', 'Escape']) -time.sleep(3) - -# Press and hold 'D' key for a duration to simulate a step -print("Holding 'D' key for a step.") -subprocess.run(['xdotool', 'keydown', 'd']) -time.sleep(0.4) # Hold 'D' for 0.4 second; adjust this duration as needed -subprocess.run(['xdotool', 'keyup', 'd']) -time.sleep(10) # Wait after the step +# Perform trading actions in a loop +for _ in range(3): # Number of trades to perform + trade_actions()