2022年9月30日 星期五

xdo on linux (按鍵精靈)

xdo, 按鍵精靈, works on XUbuntu 20.04

Install:
$ sudo apt-get install libxdo-dev libxdo3 xdotool 

Exsample:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xdo.h>
#include <unistd.h>


void mouse_left_click(const xdo_t *xdo, int x, int y)
{
    xdo_click_window(xdo, CURRENTWINDOW, Button1); //left mouse key
    return;
}

void keyboard_enter_string(const xdo_t *xdo, const char *str, size_t slen)
{
    int i=0;
    char character[2]={'\0'};

    for(i=0; i<slen; i++)
    {
        character[0]=*(str+i);
        xdo_send_keysequence_window(xdo, CURRENTWINDOW, character, 0);
    }
    return;
}

int main(void)
{
    //xdo_t *x = xdo_new(":0.0");
    xdo_t * x = xdo_new(NULL);
    xdo_send_keysequence_window(x, CURRENTWINDOW, "Alt_L+Tab", 0);
    sleep(3);

    xdo_move_mouse(x, 628, 435, CURRENTWINDOW);
    sleep(2);
    mouse_left_click(x, 0, 0);


    //xdo_send_keysequence_window(x, CURRENTWINDOW, "Alt_L+Tab", 0);
    //sleep(1);
    ////keyboard_enter_string(x, "Hello", strlen("Hello"));
    xdo_enter_text_window(x, CURRENTWINDOW, "hello world", 1000);

    //xdo_send_keysequence_window(x, CURRENTWINDOW, "KP_Enter", 0); //ok
    //xdo_send_keysequence_window(x, CURRENTWINDOW, "Alt_L+F4", 0); //ok
    //xdo_send_keysequence_window(x, CURRENTWINDOW, "Shift_L+Super_L+s", 0); //ok

    xdo_free(x);
    return 0; 
}
$ gcc example.c -o ex -lxdo

get current mouse coordinates:
$ xdotool getmouselocation --shell


ref:
1. How would I get the current mouse coordinates in bash?
2. C language - trigger key events in Linux with xdo

沒有留言:

張貼留言