
오늘은 기본 문법은 아니고 그냥 다른 일을 진행하다가 알게 된 모듈에 대해 적어 보려한다.
원래 캡처프로그램을 만들려고 알아보다가 알게 된 것인데, 마우스 클릭 시 클릭 했을 때의 좌표를 저장하는 것이다.
바로 pynput이라는 라이브러리를 통해 마우스를 제어하는 것인데, 해당 관련 자세한 사항은 아래 웹사이트에서 확인 가능하다.
https://pynput.readthedocs.io/en/latest/mouse.html
Handling the mouse — pynput 1.7.6 documentation
Parameters: on_move (callable) – The callback to call when mouse move events occur. It will be called with the arguments (x, y), which is the new pointer position. If this callback raises StopException or returns False, the listener is stopped. on_click
pynput.readthedocs.io
마우스 클릭 시 좌표를 알아내는 코드는 아래와 같다.
from pynput.mouse import Listener
coord = []
def click(x,y, button, pressed):
if pressed:
x = int(x)
y = int(y)
coord.append(x)
coord.append(y)
print(coord)
with Listener(on_click = click) as Listener:
Listener.join()
'Programming > Python' 카테고리의 다른 글
코딩 공부할 때 막혔을 때 팁! - 전문가에게 알아보자! Stack Overflow (2) | 2022.06.30 |
---|---|
직장인 필독! 이메일 자동 발송 프로그램 만들기 (파이썬 Python) (0) | 2022.06.01 |
예외처리 함수 (Try... Except 구문) - 파이썬 (Python) 문법 (7) | 2022.05.14 |
컴퓨터와 가위바위보 하기 (for in 반복문 이용) - 파이썬 (Python) 문법 (4) | 2022.05.11 |
코드업 6097 설탕막대기 두기 - 파이썬 (Python) (2) | 2022.05.03 |
댓글