๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘จ๐Ÿผ‍๐Ÿ’ป๊ฐœ๋ฐœ/ํŒŒ์ด์ฌ

ํŒŒ์ด์ฌ - PyAutoGUI๊ฐ€ ์•ˆ๋  ๊ฒฝ์šฐ ๋Œ€์ฒด ๊ฐ€๋Šฅํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(PyDirectInput)

by Janger 2023. 7. 15.
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)

ready.png

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•ด์„œ pyautogui๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๋˜ ๋””์ œ์ด๋งฅ์Šค์— ์ž๋™ ๋ ˆ๋””๋ฅผ ํ•˜๋Š” ๋งคํฌ๋กœ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด์•˜๋‹ค. 

728x90
๋ฐ˜์‘ํ˜•