def mouse(): current = win32api.GetCursorPos() cx = lead_x = int(current[0]) cy = lead_y = int(current[1]) last = time.time() while(True): if (ser.inWaiting()>0): xx=ser.readline() xx=int(xx.decode()) #print(xx) if win32api.GetAsyncKeyState(ord('X')): sys.exit() elif xx == 77: lead_x=lead_x+3 elif xx == 33: lead_x=lead_x-3 elif xx == 88: lead_y=lead_y-3 elif xx == 22: lead_y=lead_y+3 elif xx == 66: p=win32api.GetCursorPos() lclick(p[0],p[1]) elif xx == 11: p=win32api.GetCursorPos() rclick(p[0],p[1]) elif xx == 1: print("Cursor lost its control") return() #sys.exit() win32api.SetCursorPos((lead_x,lead_y)) time.sleep(0.001)
def keyState(keys): stack = [] for key in keys: state = win32api.GetAsyncKeyState(ord(key)) if(state < 0 or state == 1): stack.append(key) return stack
def main(): last_time = time.time() for i in list(range(4))[::-1]: print(i + 1) time.sleep(1) paused = False cam_url = 'http://192.168.8.110:8080/video' cam = cv2.VideoCapture(cam_url) test_rig = car('http://192.168.8.108/controls') while (True): if not paused: cam = cv2.VideoCapture(cam_url) ret, screen = cam.read() last_time = time.time() screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY) screen = cv2.resize(screen, (WIDTH, HEIGHT)) prediction = model.predict([screen.reshape(WIDTH, HEIGHT, 1)])[0] print(prediction) turn_thresh = 0.75 fwd_thresh = 0.50 if prediction[1] > turn_thresh and max( prediction) == prediction[1]: print('LEFT\n') test_rig.left() test_rig.forward() elif prediction[2] > turn_thresh and max( prediction) == prediction[2]: print('RIGHT\n') test_rig.right() test_rig.forward() elif prediction[0] > fwd_thresh: print('FORWARD\n') test_rig.forward() else: test_rig.stop() state = win32api.GetAsyncKeyState(ord('T')) if (state < 0 or state == 1): if paused: cam = cv2.VideoCapture(cam_url) paused = False time.sleep(1) else: paused = True time.sleep(1)
def key_check(): keys = [] for key in keyList: if wapi.GetAsyncKeyState(ord(key)): keys.append(key) return keys
def is_activated(): return win32api.GetAsyncKeyState(0x10) != 0
# if __debug__: # # draw the contour of the chosen target in green # cv2.drawContours(frame, [target], -1, (0, 255, 0), 2) # # draw a small white circle at their center of mass # cv2.circle(frame, (cx, cy), 7, (255, 255, 255), -1) # Main lifecycle while True: frame = np.asarray(sct.grab(dimensions)) contours = viz.process(frame) currentTime = int(round(time.time() * 1000)) if currentTime > startTime + 500 and ( win32api.GetAsyncKeyState(0x64) != 0 or win32api.GetAsyncKeyState(0x61) != 0 or win32api.GetAsyncKeyState(0x66) != 0 or win32api.GetAsyncKeyState(0x63) != 0 or win32api.GetAsyncKeyState(0x62) != 0 ) : startTime = currentTime if(win32api.GetAsyncKeyState(0x64) != 0): autoshotOn = True print("Autoshot: On") if(win32api.GetAsyncKeyState(0x61) != 0): autoshotOn = False print("Autoshot: Off") if(win32api.GetAsyncKeyState(0x66) != 0): headshotOn = True print("Headshot: On") if(win32api.GetAsyncKeyState(0x63) != 0): headshotOn = False print("Headshot: Off") if(win32api.GetAsyncKeyState(0x62) != 0): singleUseHeadshot = True
def keyDown(key): return (win32api.GetAsyncKeyState(key) & (1 << 15)) >> 15
def check(key_code): return win32api.GetAsyncKeyState(key_code) & 0x8000