[英]win32api and python causing my screen to go black when it moves the mouse
無論出於何種原因,在鼠標第二或第三次移動后,屏幕都會變黑。 首先是我用來移動鼠標的功能:
import ctypes
import time
SendInput = ctypes.windll.user32.SendInput
def MoveMouse(x, y):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
x = int(x*(65536/ctypes.windll.user32.GetSystemMetrics(0))+1)
y = int(y*(65536/ctypes.windll.user32.GetSystemMetrics(1))+1)
ii_.mi = MouseInput(x, y, 0, 0x0001 | 0x8000, 1, ctypes.pointer(extra))
x = Input(ctypes.c_ulong(0), ii_)
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
這會導致屏幕變黑
import numpy as np
from PIL import ImageGrab
import cv2
import time
import win32api, win32con
from directkeys import PressKey,ReleaseKey, W, A, S, D, MoveMouse
from grabscreen import grab_screen
x_pad = 0
y_pad = 0
def left():
PressKey(W)
PressKey(A)
#ReleaseKey(W)
ReleaseKey(D)
#ReleaseKey(A)
time.sleep(.9)
ReleaseKey(A)
def leftClick():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
print ("Click.")
def mousePos(cord):
win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1]))
def screen_record():
last_time = time.time()
while(True):
# 800x600 windowed mode for GTA 5, at the top left position of your main screen.
# 40 px accounts for title bar.
printscreen = grab_screen(region=(0,40,800,640))
#rgb_im = printscreen.convert('RGB')
pixels =int(printscreen[300, 300, 0])
print(pixels)
#r, g, b = printscreen.getpixel((551, 350 ))
if pixels == 255:
#if r == 127and g == 26 and b == 25:
x, y = win32api.GetCursorPos()
#x += 44
time.sleep(1)
MoveMouse(x, y)
time.sleep(1)
#
#print (r, g, b)
screen_record()
謝謝任何幫助,將不勝感激。 總而言之,我需要幫助確定為什么“移動鼠標”功能會導致我的整個台式機顯示器變黑,直到不再使用該功能為止。
遇到相同的問題,請嘗試更改:
ii_.mi = MouseInput(x, y, 0, 0x0001 | 0x8000, 1, ctypes.pointer(extra))
第五個參數(即“ 1”)為0,因此如下所示:
ii_.mi = MouseInput(x, y, 0, 0x0001 | 0x8000, 0, ctypes.pointer(extra))
為我工作...祝你好運
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.