๐จ๐ผ๐ป๊ฐ๋ฐ/ํ์ด์ฌ
ํ์ด์ฌ - PyAutoGUI๊ฐ ์๋ ๊ฒฝ์ฐ ๋์ฒด ๊ฐ๋ฅํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(PyDirectInput)
Janger
2023. 7. 15. 03:39
728x90
๊ธฐ๋ณธ PyAutoGUI๋ ๊ฐ์ ํค(VK)์ mouse_event() ๋ฐ keybd_event() win32 ํจ์๋ฅผ ์ฌ์ฉํ๊ณ ์๋๋ฐ ์ด๋ ์ผ๋ถ ์์ฉ ํ๋ก๊ทธ๋จ๋ค, ๋น๋์ค ๊ฒ์์ด๋ DirectX์ ์ง์ํ์ง ์์ ์ ๋๋ก ์๋ํ์ง ์์ ์ ์๋ค. ๊ทธ๋์ PyDirectInput ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ DirectInput ์ค์บ ์ฝ๋์ SendInput() win32 ๊ฐ์ ์ต์ ๋ฐฉ์์ ์ฌ์ฉํด ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ค.
PyPi - PyDirectInput
https://pypi.org/project/PyDirectInput/
PyDirectInput
Python mouse and keyboard input automation for Windows using Direct Input.
pypi.org
์ฝ๋ ์์
>>> import pyautogui
>>> import pydirectinput
>>> pydirectinput.moveTo(100, 150) # Move the mouse to the x, y coordinates 100, 150.
>>> pydirectinput.click() # Click the mouse at its current location.
>>> pydirectinput.click(200, 220) # Click the mouse at the x, y coordinates 200, 220.
>>> pydirectinput.move(None, 10) # Move mouse 10 pixels down, that is, move the mouse relative to its current position.
>>> pydirectinput.doubleClick() # Double click the mouse at the
>>> pydirectinput.press('esc') # Simulate pressing the Escape key.
>>> pydirectinput.keyDown('shift')
>>> pydirectinput.keyUp('shift')
๋์ ์ด๋งฅ์ค ์๋ ๋ ๋ ๋งคํฌ๋ก
import pyautogui
import pydirectinput
import time
ready_delay = 3
while True:
time.sleep(0.5)
result1 = pyautogui.locateCenterOnScreen('ready.png')
print("๋ ๋ ์ํ ์๋.")
if result1 != None:
for i in range(1, ready_delay+1):
print( "๋ ๋ ๋๊ธฐ " + str(i) + "์ด ๊ฒฝ๊ณผ " )
result2 = pyautogui.locateCenterOnScreen('ready.png')
if result2 == None:
break
if i >= (ready_delay) and result2 != None:
pydirectinput.press('f5')
print("F5 ๋๋ฆ.")
for j in range(1, 300+1):
time.sleep(1)
print( "๋ ๋ ํ " + str(j) + "์ด ๊ฒฝ๊ณผ " )
result3 = pyautogui.locateCenterOnScreen('ready.png')
if result3 == None:
print('๋ ๋ ํด์ ๋จ.')
break
time.sleep(1)
์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด์ pyautogui๊ฐ ์๋ํ์ง ์๋ ๋์ ์ด๋งฅ์ค์ ์๋ ๋ ๋๋ฅผ ํ๋ ๋งคํฌ๋ก๋ฅผ ์์ฑํด ๋ณด์๋ค.
728x90