Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <xcb/xcb.h>
- #include <xcb/xcb_keysyms.h>
- #include <xcb/xtest.h>
- #include <xcb/xcb_util.h>
- #include <unistd.h>
- #include <stdlib.h>
- /* xcb_test_fake_input(type,detail,time,window,x,y,device) */
- static void
- fake_input(xcb_connection_t *c, uint8_t type, uint8_t detail)
- {
- xcb_window_t none = { XCB_NONE };
- xcb_test_fake_input( c, type, detail, 0, none, 0, 0, 0 );
- }
- static void
- fake_motion(xcb_connection_t *c, uint8_t relative, uint16_t x, uint16_t y)
- {
- xcb_window_t window = { XCB_NONE };
- if (!relative) {
- window = xcb_setup_roots_iterator(xcb_get_setup(c)).data->root;
- }
- xcb_test_fake_input( c, XCB_MOTION_NOTIFY, relative, 0, window, x, y, 0 );
- }
- void send_key( xcb_connection_t *c, char code ) {
- fake_input( c, XCB_KEY_PRESS, code );
- fake_input( c, XCB_KEY_RELEASE, code );
- }
- void mouse_click( xcb_connection_t *c, int button ) {
- fake_input( c, XCB_BUTTON_PRESS, button );
- fake_input( c, XCB_BUTTON_RELEASE, button );
- }
- void mouse_move( xcb_connection_t *c, int x, int y ) {
- fake_motion( c, 0, x, y );
- }
- void mouse_rel_move( xcb_connection_t *c, int x, int y ) {
- fake_motion( c, 1, x, y );
- }
- void process_command( xcb_connection_t *c) {
- int x, y;
- for(y = 0; y < 800; y+=20)
- {
- for(x = 0; x < 1280; x+=20)
- {
- mouse_move( c, x,y );
- usleep(10000);
- xcb_flush( c );
- }
- }
- // fake_input( c, XCB_KEY_PRESS, 6);
- //fake_input( c, XCB_KEY_RELEASE, 6 );
- }
- int main( int argc, char *argv[] ) {
- xcb_connection_t *c = NULL;
- char *display = NULL;
- c = xcb_connect( display, NULL );
- if( c == NULL ) {
- fprintf( stderr, "Unable to open display '%s'\n", display == NULL ? "default" : display );
- exit( 1 );
- }
- process_command( c);
- xcb_disconnect( c );
- exit( 0 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement