Skip to content

sleep 1s after UI_DEV_CREATE #213

Description

@tillthendofworld

int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
......
ioctl(fd, UI_DEV_CREATE);
/*
* On UI_DEV_CREATE the kernel will create the device node for this
* device. We are inserting a pause here so that userspace has time
* to detect, initialize the new device, and can start listening to
* the event, otherwise it will not notice the event we are about
* to send.
*/
//sleep(1);
write(...); // not work, if not sleep(1)

https://kernel.org/doc/html/v4.12/input/uinput.html#examples

    '''  a not work example, draw circle inf, 
         the first BTN_TOUCH,1 is ignored because the device not created'''
    def draw_cricle(x0=600,y0=1493,n=4,r=50):
         n=int(n)
         for k in range(0,n):
             angle = 2*math.pi*(k/n+3/4)
             x = r*math.cos(angle)+x0
             y = r*math.sin(angle)+y0
             yield int(x),int(y)
     code= ''
     self.TRACKING_ID+=1
     code+= f'// {x0},{y0}\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_SLOT, {int(slot_id)});\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_TRACKING_ID, {int(self.TRACKING_ID)});\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_X, {int(x0)});\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_Y, {int(y0)});\n'
     code+= f'emit(uinputfd, EV_KEY, BTN_TOUCH, 1);\n'
     code+= f'emit(uinputfd, EV_SYN, SYN_REPORT, 0);\n'
     code+= '''while(1) {\n'''
     for idx,(x,y) in enumerate(draw_cricle()):
         code+= f'  usleep({int(s*1000000)});//{s}s\n' #s=0.01 s
         code+= f'// move {x},{y}\n'
         # code+= f'emit(uinputfd, EV_ABS, ABS_MT_SLOT, {int(slot_id)});\n'
         code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_X, {int(x)});\n'
         code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_Y, {int(y)});\n'
         code+= f'emit(uinputfd, EV_SYN, SYN_REPORT, 0);\n'
     code+= '''}         \n'''

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions