Linuxinputsubsystem virtual keyboard and mouse

Source: Internet
Author: User
Article Title: linuxinputsubsystem virtual keyboard and mouse. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

1 event device

In/dev/input/event?

Cat data from/dev/input/event? The data format is:

Struct input_event {

Struct timeval time;

_ 2010type;

_ 2010code;

_ S32 value;

};

E. g:

Xx yy tt cc vv

Xx is usec

Yy is sec

Tt is type

Cc is key code

Vv is value, might be it means keyup or keydown

For mouse event, you can get the same message format

Xx, yy is the same as keyboard

Tt is EV_REL, it means the value feild is relative distance;

Cc is REL_X or REL_Y

Vv is the value of relative distance

2 register input_dev

/**************************

For virtual mouse

**/

Static int vkm_vmouse_register (void)

{

Struct input_dev * vmouse_dev;

Vmouse_dev = input_allocate_device ();

If (! Vmouse_dev)

Return-ENOMEM;

Vmouse_dev-> name = "VMouse ";

Vmouse_dev-> phys = "xxmouse/input1 ";

Vmouse_dev-> id. bustype = BUS_HOST;

Vmouse_dev-> id. vendor = 0x0001;

Vmouse_dev-> id. product = 0x0002;

Vmouse_dev-> id. version = 0x0100;

Vmouse_dev-> evbit [0] = BIT_MASK (EV_KEY) | BIT_MASK (EV_REL );

Vmouse_dev-> keybit [BIT_WORD (BTN_MOUSE)] =

BIT_MASK (BTN_LEFT) | BIT_MASK (BTN_RIGHT );

Vmouse_dev-> relbit [0] = BIT_MASK (REL_X) | BIT_MASK (REL_Y );

/* Error check */

Error = input_register_device (vmouse_dev );

If (error ){

Input_free_device (vmouse_dev );

Return error;

}

}

/**************************

For virtual keyboard

**/

Static int vkm_vkbd_register (void)

{

Int I, error;

Struct input_dev * vkbd_dev;

Vkbd_dev = input_allocate_device ();

If (! Vkbd_dev)

Return-ENOMEM;

Vkbd_dev-> name = "VKBD Keyboard ";

Vkbd_dev-> phys = "atakbd/input0 ";

Vkbd_dev-> id. bustype = BUS_HOST;

Vkbd_dev-> id. vendor = 0x0001;

Vkbd_dev-> id. product = 0x0001;

Vkbd_dev-> id. version = 0x0100;

Vkbd_dev-> evbit [0] = BIT_MASK (EV_KEY) | BIT_MASK (EV_REP );

Vkbd_dev-> keycode = atakbd_keycode;

Vkbd_dev-> keycodesize = sizeof (unsigned char );

Vkbd_dev-> keycodemax = ARRAY_SIZE (atakbd_keycode );

For (I = 1; I <0x72; I ++ ){

Set_bit (atakbd_keycode [I], vkbd_dev-> keybit );

}

/* Error check */

Error = input_register_device (vkbd_dev );

If (error ){

Input_free_device (vkbd_dev );

Return error;

}

Return 0;

}

Send keyboard event to input handler like this:

Input_report_key (vkbd_dev, KEY_A, 0 );

Input_sync (vkbd_dev );

And send mouse event to input handler like this:

Input_report_rel (vmouse_dev, REL_X, 10 );

Input_report_rel (vmouse_dev, REL_Y, 10 );

Input_sync (vmouse_dev );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.