Reputation: 315
For whatever reason the screen is going black after the second or third movement of the mouse. First is the function i use to move 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))
this causes the screen to go black
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()
Thanks any help would be appreciated. To summarize i need help determining why the Move Mouse function is causing my entire desktop monitor to black out until the function is no longer being used.
Upvotes: 0
Views: 403
Reputation: 36
Had the same issue, try changing in:
ii_.mi = MouseInput(x, y, 0, 0x0001 | 0x8000, 1, ctypes.pointer(extra))
the fifth parameter (I.E. "1") to a 0, so it looks like this:
ii_.mi = MouseInput(x, y, 0, 0x0001 | 0x8000, 0, ctypes.pointer(extra))
Worked for me... Good luck
Upvotes: 1