somethingworks
This commit is contained in:
20
mousexy
Normal file
20
mousexy
Normal file
@@ -0,0 +1,20 @@
|
||||
import pyautogui
|
||||
import keyboard
|
||||
|
||||
print("Press 'c' to capture the mouse position. Press 'Esc' to exit.")
|
||||
|
||||
while True:
|
||||
try:
|
||||
if keyboard.is_pressed('c'):
|
||||
x, y = pyautogui.position()
|
||||
print(f"Position captured: {x}, {y}")
|
||||
elif keyboard.is_pressed('æ'):
|
||||
print("Exiting.")
|
||||
break
|
||||
except RuntimeError:
|
||||
continue
|
||||
#right click: 2725, 1203
|
||||
#drag click: 2600, 1399
|
||||
#left click: 2450, 1408
|
||||
#shift click: 2994, 1105
|
||||
# key D D
|
||||
58
trade2.py
Normal file
58
trade2.py
Normal file
@@ -0,0 +1,58 @@
|
||||
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(10)
|
||||
|
||||
drag_slider(2600, 1399, 2600, 1408)
|
||||
time.sleep(10)
|
||||
|
||||
click(2450, 1408)
|
||||
time.sleep(10)
|
||||
|
||||
shift_click(2994, 1105)
|
||||
time.sleep(10)
|
||||
|
||||
# Press 'D' key twice
|
||||
print("Pressing 'D' key.")
|
||||
subprocess.run(['xdotool', 'key', 'd'])
|
||||
time.sleep(10)
|
||||
subprocess.run(['xdotool', 'key', 'd'])
|
||||
98
trader.py
98
trader.py
@@ -1,66 +1,58 @@
|
||||
import pyautogui
|
||||
import cv2
|
||||
import numpy as np
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
def find_on_screen(template, threshold=0.8):
|
||||
screen = np.array(pyautogui.screenshot())
|
||||
gray_screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
|
||||
res = cv2.matchTemplate(gray_screen, template, cv2.TM_CCOEFF_NORMED)
|
||||
loc = np.where(res >= threshold)
|
||||
if loc[0].size:
|
||||
return loc[1][0], loc[0][0]
|
||||
return None
|
||||
def right_click(x, y):
|
||||
move_mouse(x, y)
|
||||
print("Performing right click.")
|
||||
subprocess.run(['xdotool', 'click', '3']) # Right-click
|
||||
|
||||
def load_images():
|
||||
images = {
|
||||
'cleric': cv2.imread('/home/alex/minecraft/pybot/screenshot_folder/cleric.png', 0),
|
||||
'trade_window_top': cv2.imread('/home/alex/minecraft/pybot/screenshot_folder/trade_window_top.png', 0),
|
||||
'trade_window_bottom': cv2.imread('/home/alex/minecraft/pybot/screenshot_folder/trade_window_bottom.png', 0),
|
||||
'trade_window_potion_click': cv2.imread('/home/alex/minecraft/pybot/screenshot_folder/trade_window_potion_click.png', 0),
|
||||
'shift_click_potion': cv2.imread('/home/alex/minecraft/pybot/screenshot_folder/shift_click_potion.png', 0),
|
||||
'trade_blocked': cv2.imread('/home/alex/minecraft/pybot/screenshot_folder/trade_blocked.png', 0)
|
||||
}
|
||||
return images
|
||||
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 right_click(pos):
|
||||
pyautogui.rightClick(pos)
|
||||
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 drag_slider(top_pos, bottom_pos):
|
||||
pyautogui.moveTo(top_pos)
|
||||
pyautogui.dragTo(bottom_pos, duration=1)
|
||||
def move_mouse(x, y):
|
||||
subprocess.run(['xdotool', 'mousemove', str(x), str(y)])
|
||||
|
||||
def click(pos):
|
||||
pyautogui.click(pos)
|
||||
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)
|
||||
|
||||
def shift_click(pos):
|
||||
pyautogui.keyDown('shift')
|
||||
click(pos)
|
||||
pyautogui.keyUp('shift')
|
||||
# Initial setup
|
||||
focus_minecraft_window()
|
||||
|
||||
images = load_images()
|
||||
cleric_pos = find_on_screen(images['cleric'])
|
||||
if cleric_pos:
|
||||
right_click(cleric_pos)
|
||||
time.sleep(1) # Wait for the trade window to open
|
||||
# Perform actions
|
||||
right_click(2725, 1203)
|
||||
time.sleep(10)
|
||||
|
||||
# Drag the trade window slider from top to bottom
|
||||
top_pos = find_on_screen(images['trade_window_top'])
|
||||
bottom_pos = find_on_screen(images['trade_window_bottom'])
|
||||
if top_pos and bottom_pos:
|
||||
drag_slider(top_pos, bottom_pos)
|
||||
drag_slider(2600, 1399, 2600, 1408)
|
||||
time.sleep(10)
|
||||
|
||||
# Click on the potion trade
|
||||
potion_pos = find_on_screen(images['trade_window_potion_click'])
|
||||
if potion_pos:
|
||||
click(potion_pos)
|
||||
click(2450, 1408)
|
||||
time.sleep(10)
|
||||
|
||||
# Shift-click on the potion in the player's inventory
|
||||
shift_click_pos = find_on_screen(images['shift_click_potion'])
|
||||
if shift_click_pos:
|
||||
shift_click(shift_click_pos)
|
||||
shift_click(2994, 1105)
|
||||
time.sleep(10)
|
||||
|
||||
# Check if the trade is blocked
|
||||
if find_on_screen(images['trade_blocked']):
|
||||
print("Trade done")
|
||||
# Press 'D' key twice
|
||||
print("Pressing 'D' key.")
|
||||
subprocess.run(['xdotool', 'key', 'd'])
|
||||
time.sleep(10)
|
||||
subprocess.run(['xdotool', 'key', 'd'])
|
||||
|
||||
Reference in New Issue
Block a user