[기본 사용 방식 및 사용 예시]

1
2
3
4
5
6
# 현재 마우스 위치의 (x, y)좌표 반환
pyautogui.position() 
 
# 사용 예시
x, y = pyautogui.position()
print("x={0},y={1}".format(x,y)) 
cs

1
2
3
4
5
6
# 모니터 해상도 (가로, 세로) 반환
pyautogui.size()
 
# 사용 예시
width, height = pyautogui.size()  
print('width={0}, height={1}'.format(width, height)) 
cs

1
2
3
4
5
6
# 해당 좌표에 마우스 커서 시간 동안 이동
pyautogui.moveTo(x좌표, y좌표, 시간) 
 
# 사용 예시
pyautogui.moveTo(1001002)  
pyautogui.moveTo(2002002)
cs

1
2
# 안전모드 설정하기, 잘못되었을 경우 탈출구
pyautogui.FAILSAFE = True (False 값을 넣을 경우 오류 발생시 실행 멈추지 않음)
cs

1
2
3
4
5
# 상대좌표로 마우스 이동하기 ( 현재위치에서 참조값만큼 마우스 이동)
pyautogui.moveRel(x축 참조값, y축 참조값, 시간)
 
# 사용 예시
pyautogui.moveRel(None, 120,2)
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 마우스 클릭하기
pyautogui.click()
 
# 마우스로 특정좌표 클릭하기
pyautogui.click(x=823, y=584)
 
# 마우스 오른쪽 클릭하기
pyautogui.click(button='right')
pyautogui.rightClick()  
 
# 마우스로 더블 클릭하기
pyautogui.click(clicks=2)
pyautogui.doubleClick()
 
# 시간 간격(인터벌)을 가지고 클릭하기
pyautogui.click(clicks=2, interval=1.5)  
 
# 마우스 버튼다운
pyautogui.mouseDown()
 
# 마우스 버튼업
pyautogui.mouseUp()  
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 마우스 드래그 - 방법 1
pyautogui.mouseDown(x=261, y=12)
pyautogui.mouseUp(x=0, y=197)  
 
# 마우스 드래그 - 방법 2
# 마우스 현재 위치에서 x=100, y=100로 드래그
pyautogui.dragTo(x=100, y=100)
 
# 중간 지연 시간을 가지고 마우스 현재 위치에서 x=100, y=100로 드래그
pyautogui.dragTo(x=100, y=100, duration=2)  
 
# # 상대 좌표를 가지고 마우스 드래그
pyautogui.dragRel(-100-100, duration=2
 
cs

1
2
3
4
5
6
7
8
9
10
# 마우스 스크롤
 
# 위로
pyautogui.scroll(-100)
 
# 아래로
pyautogui.scroll(100)
 
# 특정 위치로 이동(x=100, y=100) 후 스크롤
pyautogui.scroll(100, x=100, y=100
cs

1
2
3
4
5
6
7
8
9
10
11
# 특정 문자열 입력하기
pyautogui.typewrite('Hello!')
 
# 특정 문자열 안정적으로 입력하기
time.sleep(1)  
pyautogui.typewrite('Hello!', interval=0.25)
 
# 한글 입력은 안 됨
pyautogui.typewrite('한글!'
#글을 적는 곳의 IME가 한글로 설정되어 있다면 영타로 쳐서 한글입력 가능
pyautogui.typewrite('gksrmf!'
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 엔터키 누르기
pyautogui.press('enter')
 
# 여러 키 연속으로 입력하기
pyautogui.press(['backspace''enter'])
 
# press 가능 키 리스트
['\t''\n''\r'' ''!''"''#''$''%''&'"'"'(',
')''*''+'',''-''.''/''0''1''2''3''4''5''6''7',
'8''9'':'';''<''=''>''?''@''[''\\'']''^''_''`',
'a''b''c''d''e','f''g''h''i''j''k''l''m''n''o',
'p''q''r''s''t''u''v''w''x''y''z''{''|''}''~',
'accept''add''alt''altleft''altright''apps''backspace',
'browserback''browserfavorites''browserforward''browserhome',
'browserrefresh''browsersearch''browserstop''capslock''clear',
'convert''ctrl''ctrlleft''ctrlright''decimal''del''delete',
'divide''down''end''enter''esc''escape''execute''f1''f10',
'f11''f12''f13''f14''f15''f16''f17''f18''f19''f2''f20',
'f21''f22''f23''f24''f3''f4''f5''f6''f7''f8''f9',
'final''fn''hanguel''hangul''hanja''help''home''insert''junja',
'kana''kanji''launchapp1''launchapp2''launchmail',
'launchmediaselect''left''modechange''multiply''nexttrack',
'nonconvert''num0''num1''num2''num3''num4''num5''num6',
'num7''num8''num9''numlock''pagedown''pageup''pause''pgdn',
'pgup''playpause''prevtrack''print''printscreen''prntscrn',
'prtsc''prtscr''return''right''scrolllock''select''separator',
'shift''shiftleft''shiftright''sleep''space''stop''subtract''tab',
'up''volumedown''volumemute''volumeup''win''winleft''winright''yen',
'command''option''optionleft''optionright']
 
# 조합 키 입력하기 (쉬프트 누르고 왼쪽으로 한 칸 선택한 후, 쉬프트 떼기)
pyautogui.keyDown('shift')  
pyautogui.press('left')  
pyautogui.keyUp('shift')  
 
# 복사 붙이기
# Ctrl + C (단축키 = hotkey)
pyautogui.hotkey('ctrl''c')
 
# Ctrl + V
pyautogui.hotkey('ctrl''v'
 
cs


+ Recent posts