Aus irgendeinem Grund wird der Bildschirm nach der zweiten oder dritten Bewegung der Maus schwarz. Erstens ist die Funktion i verwenden, um die Maus zu bewegen:win32api und python, was dazu führt, dass mein Bildschirm schwarz wird, wenn er die Maus bewegt
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))
die Bildschirmfläche verursacht schwarz
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()
Dank jede Hilfe würde geschätzt zu gehen. Zusammenfassend muss ich herausfinden, warum die Move Mouse-Funktion dazu führt, dass mein gesamter Desktop-Monitor schwarz wird, bis die Funktion nicht mehr verwendet wird.
Ich sollte erwähnen, es ist ein ähnliches Problem zu diesem: http://stackoverflow.com/questions/27674827/python-mouse-movement-emulation-in-games/29956868#29956868 Ich versuche um es in einem Videospiel zu betreiben. aber es funktioniert auch nicht, wenn ich es nur auf dem Desktop benutze. pyautogui wird nicht arbeiten. Ich bin in Python 3.5 und Windows 10 – Daveyman123