How can I get the current mouse (pointer) position co-ordinates in X

前端 未结 4 1297
故里飘歌
故里飘歌 2020-12-14 02:21

This can either be some sample C code or a utility that will show me either gui or on the console it doesn\'t matter, but I have to be able to \"command\" it to grab the co-

4条回答
  •  天命终不由人
    2020-12-14 03:08

    xinput can be used to print the full device state of any input device.

    First you need to discover your device id:

    $ xinput --list | grep -i mouse                                                                                                                                
    ⎜   ↳ Logitech USB Receiver Mouse               id=11   [slave  pointer  (2)]
    

    then you can ask for state:

    $ xinput --query-state 11;
    2 classes :
    ButtonClass
            button[1]=up
            button[2]=up
            button[3]=up
            button[4]=up
            button[5]=up
            button[6]=up
            button[7]=up
            button[8]=up
            button[9]=up
            button[10]=up
            button[11]=up
            button[12]=up
            button[13]=up
            button[14]=up
            button[15]=up
            button[16]=up
            button[17]=up
            button[18]=up
            button[19]=up
            button[20]=up
    ValuatorClass Mode=Relative Proximity=In
            valuator[0]=274
            valuator[1]=886
            valuator[2]=0
            valuator[3]=675
    

    Or just a loop:

    while sleep .2; do xinput --query-state $(xinput --list | grep -i mouse | cut -d= -f2 | cut -f1| head -1); done
    

提交回复
热议问题