2017-05-03 51 views
0

无论出于何种原因,在鼠标的第二次或第三次移动之后屏幕都变黑。首先是我用它来移动鼠标的功能:win32api和python导致我的屏幕在移动鼠标时变黑。

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() 

感谢任何帮助,将不胜感激。总结一下,我需要帮助确定为什么移动鼠标功能导致我的整个桌面显示器变黑,直到不再使用此功能。

+0

我应该提到它是一个类似的问题,这个:http://stackoverflow.com/questions/27674827/python-mouse-movement-emulation-in-games/29956868#29956868我想在视频游戏中运行它。但它也不工作,即时通讯在桌面上使用它。 pyautogui不会工作。我在Python 3.5和Windows 10 – Daveyman123

回答

1

有同样的问题,尝试改变:

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)) 

为我工作。 .. 祝你好运

相关问题