예제 #1
0
def EngageCursorHold(flag=True):
    global bHoldCursor, cursorPos
    if flag:
        print("Locking cursor...")
        bHoldCursor = True
        cursorPos = win32api.GetCursorPos()
        win32api.ClipCursor((cursorPos[0] - 1, cursorPos[1] - 1,
                             cursorPos[0] + 1, cursorPos[1] + 1))
    else:
        win32api.ClipCursor()
        bHoldCursor = False
        print("Cursor unlocked!")
예제 #2
0
def pointer_grab(window, *args):
    hwnd = get_window_handle(window)
    grablog("pointer_grab%s window=%s, hwnd=%s", args, window, hwnd)
    if not hwnd:
        window._client.pointer_grabbed = False
        return
    wx1,wy1,wx2,wy2 = win32gui.GetWindowRect(hwnd)
    grablog("GetWindowRect(%i)=%s", hwnd, (wx1,wy1,wx2,wy2))
    try:
        DwmGetWindowAttribute = ctypes.windll.dwmapi.DwmGetWindowAttribute
        # Vista & 7 stuff
        rect = ctypes.wintypes.RECT()
        DWMWA_EXTENDED_FRAME_BOUNDS = 9
        DwmGetWindowAttribute(HWND(hwnd), DWORD(DWMWA_EXTENDED_FRAME_BOUNDS), byref(rect), sizeof(rect))
        #wx1,wy1,wx2,wy2 = rect.left, rect.top, rect.right, rect.bottom
        grablog("DwmGetWindowAttribute: DWMWA_EXTENDED_FRAME_BOUNDS(%i)=%s", hwnd, (rect.left, rect.top, rect.right, rect.bottom))
    except WindowsError as e:           #@UndefinedVariable
        grablog("no DwmGetWindowAttribute: %s", e)
    bx = win32api.GetSystemMetrics(win32con.SM_CXSIZEFRAME)
    by = win32api.GetSystemMetrics(win32con.SM_CYSIZEFRAME)
    top = by
    style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE)
    if style & win32con.WS_CAPTION:
        top += win32api.GetSystemMetrics(win32con.SM_CYCAPTION)
    grablog(" window style=%s, SIZEFRAME=%s, top=%i", style_str(style), (bx, by), top)
    clip = (wx1+bx, wy1+top, wx2-bx, wy2-by)
    grablog("ClipCursor%s", clip)
    win32api.ClipCursor(clip)
    window._client.pointer_grabbed = True
예제 #3
0
def pointer_ungrab(window, *args):
    hwnd = get_window_handle(window)
    grablog("pointer_ungrab%s window=%s, hwnd=%s", args, window, hwnd)
    if hwnd:
        rect = (0,0,0,0)
        grablog("ClipCursor%s", rect)
        win32api.ClipCursor(rect)
    window._client.pointer_grabbed = False
예제 #4
0
    def clickMouse(self, mouse_down_event, mouse_up_event, x, y):

        x += self.left
        y += self.top

        current_hwnd = win32gui.GetForegroundWindow()
        current_cursor_pos = win32gui.GetCursorPos()

        #win32gui.SetForegroundWindow(self.hwnd)
        win32api.ClipCursor((x-1,y-1,x+1,y+1))
        win32api.SetCursorPos((x,y))
        win32api.mouse_event(mouse_down_event| \
                                win32con.MOUSEEVENTF_ABSOLUTE,0,0)
        win32api.mouse_event(mouse_up_event| \
                                win32con.MOUSEEVENTF_ABSOLUTE,0,0)
        win32api.ClipCursor((0,0,0,0))

        win32gui.SetForegroundWindow(current_hwnd)
        win32api.SetCursorPos(current_cursor_pos)
예제 #5
0
def cursor(self):  # 커서 가두기
    while True:
        width, height = self.GetSize()
        win32api.ClipCursor((0, 0, width - 2, height))
        time.sleep(1)
예제 #6
0
#(2, (4480, 1440), (2560, 1440), (1920, 1080))#运行结果:屏幕数量、总屏幕尺寸、主屏幕尺寸、副屏尺寸
"""
import os
import time
#import  wx
from ctypes import windll
import win32gui, win32con
import win32api
from win32api import GetSystemMetrics

from logprint import errorMsg
print("sdfasdf")
print(win32api.GetCursorPos())
#win32api.MessageBox(0,"Hello PYwin32","MessageBox",win32con.MB_OK | win32con.MB_ICONWARNING)
windll.user32.SetCursorPos(1152, 770)  # 点击当前坐标
time.sleep(2)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 1156, 766, 0, 0)

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 1156, 766, 0, 0)
rect = (0, 0, 1440, 900)
#win32api.ClipCursor(rect)
#time.sleep(8)
rect = (0, 0, 10, 10)
win32api.ClipCursor(rect)
time.sleep(3)
win32api.ClipCursor()
errorMsg('运行了主文件')

time.sleep(3)
print("qqqqqq")
예제 #7
0
import win32api as winapi

try:
    winapi.ClipCursor(1, 1, 1, 1)

except Exception as e:
    print("{}".format(e))
예제 #8
0
파일: klgr.py 프로젝트: yrasiq/DMF
import time
import win32api
import win32con
import os.path

name = 'Inpt'
check = os.path.exists(name + '.txt')
starttime = time.perf_counter()
back = ''
t2 = 0
text = []

while win32api.GetAsyncKeyState(48) == 0:
    win32api.ClipCursor((520, 1, 1400, 1919))

    t = time.perf_counter() - starttime

    mousepos = win32api.GetCursorPos()

    mousekeys = [
        win32api.GetAsyncKeyState(win32con.VK_LBUTTON),
        win32api.GetAsyncKeyState(win32con.VK_RBUTTON),
        win32api.GetAsyncKeyState(win32con.VK_MBUTTON)
    ]

    keybd = []
    for i in range(127):
        keybd.append(win32api.GetAsyncKeyState(i))

    if (mousepos, keybd, mousekeys) != back and (t - t2) > 0: