23
Jul
08

move and click mouse with xlib

how to move your mouse’s cursor without mouse ????

can you ?

so the answer is,… using some application. What kind application ?

Google said … ???? no answer

so you have to make your own application, using C programming and XLIB from Linux so you can control your mouse cursor.

so this is the source code :

=====

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

void mouseMove(int x, int y)
{
Display *displayMain = XOpenDisplay(NULL);

if(displayMain == NULL)
{
fprintf(stderr,”Error”);
exit(EXIT_FAILURE);
}

XWarpPointer(displayMain, None, None, 0,0,0,0, x, y);

XCloseDisplay(displayMain);
}

void mouseClick(int button)
{
Display *display = XOpenDisplay(NULL);
XEvent event;

if(display == NULL)
{
fprintf(stderr, “Errore nell’apertura del Display !!!\n”);
exit(EXIT_FAILURE);
}

memset(&event, 0×00, sizeof(event));

event.type = ButtonPress;
event.xbutton.button = button;
event.xbutton.same_screen = True;

XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);

event.xbutton.subwindow = event.xbutton.window;

while(event.xbutton.subwindow)
{
event.xbutton.window = event.xbutton.subwindow;

XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
}

if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, “Errore nell’invio dell’evento !!!\n”);

XFlush(display);
usleep(100000);

event.type = ButtonRelease;
event.xbutton.state = 0×100;

if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, “Errore nell’invio dell’evento !!!\n”);

XFlush(display);

XCloseDisplay(display);
}

int main(int argc, char** argv )
{

mouseMove(atoi(argv[1]),atoi(argv[2]));
mouseClick(atoi(argv[3]));

return 0;
}

=======

save this source code into some file, example mouse.c

you can compile this sourcecode using gcc :

# gcc -o mouse mouse.c -lX11

and run this program with

# ./mouse 100 100 0

with this application you can move x = 100 and y = 100 pixel without click

# ./mouse 0 0 1

with this application you can click on the spot


6 Responses to “move and click mouse with xlib”


  1. August 14, 2008 at 10:33 pm

    KLo ga pake mouse pake apa pak ????

    “with this application you can click on the spot”

    maksudnya…..

  2. August 15, 2008 at 7:15 am

    weeeeehhhh

    emang ga pake moues,… tapi cursornya kan masih ada,… jadi walaupun ga ada mousenya, kita tetep bisa klik sana sini

    misal buat virtual mouse,… gerakin mouse pake tangan kita dengan di capture pake webcam

    zaki kamu sekarang kerja dimana oe ????

  3. August 15, 2008 at 7:28 am

    Bukane wis ngerti pak….. :-D

    Posennng pak…kerjone shift2-pan….libur e ga tentu pisan…isok senen,selasa,rabu…hari libur malah masuk…. Bisa Gila…..

    Tp dilakoni sik ae…kabeh onok hikmah e….bener ga pak….:-D

    yo wis pak aq mole sik, turu … :-D ( hbs shift malam )

  4. August 15, 2008 at 7:31 am

    lo kerjo nang endi ???

    heheh nikmati ae wes… selamat bekerja ya…

    eh salah,… met bobok wekekekek

  5. August 17, 2008 at 8:06 am

    nek Indosat pak…..perasaan wis tak kandani dech…..

    yek opo pak..ga enek proyekan maneh… :-D

  6. 6 patrick
    September 3, 2008 at 6:33 am

    Thank you for this cool program.
    It helped me a lot.


Leave a Reply




 

July 2008
M T W T F S S
« Jun   Aug »
 123456
78910111213
14151617181920
21222324252627
28293031  

Y! Status : isengah

Blog Stats

  • 33,083 hits

Dual Screen Wallpaper

linux_vs_windows_by_WorteLZijNiSFijN

Guitar_Dualscreen_Wallpaper_by_lollylan

Girl_And_Guitar___Dual_Screen_by_mattyjstone

Piano_and_Guitar_by_rclop472

Misc_Macro_12_by_tienod

More Photos