1# Copyright 2024 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# pytype: skip-file 6 7# This script is to be run directly on a ChromeOS device to emulate a mouse and 8# then move to and click a location. 9 10import sys 11import time 12import uinput 13 14screen_width = int(sys.argv[1]) 15screen_height = int(sys.argv[2]) 16click_duration = float(sys.argv[3]) 17x = int(sys.argv[4]) 18y = int(sys.argv[5]) 19 20events = ( 21 uinput.ABS_X + (0, screen_width, 0, 0), 22 uinput.ABS_Y + (0, screen_height, 0, 0), 23 uinput.BTN_LEFT, 24 uinput.BTN_RIGHT, 25) 26 27with uinput.Device(events) as device: 28 # The system needs a bit of time before it can start processing events from 29 # the newly registered device. 30 time.sleep(0.1) 31 32 device.emit(uinput.ABS_X, x, syn=False) 33 device.emit(uinput.ABS_Y, y) 34 35 device.emit(uinput.BTN_LEFT, 1) 36 time.sleep(click_duration) 37 device.emit(uinput.BTN_LEFT, 0) 38