简体   繁体   中英

How can I get cursor position with Gtkmm?

Which Gtkmm functions can help me get the position(x,y) of the cursor. According to this , C# has

Gdk.Display.Default.WarpPointer(Gdk.Display.DefaultScreen, 20, 20);

Windows has

GetCursorPos

Qt has

QCursor::pos()

Gtkmm has what?

Here you are.

#include <stdio.h>
#include <gtkmm.h>

int main(int argc, char* argv[]) {
    Gtk::Main gtkm(argc, argv);
    Glib::RefPtr<Gdk::Display> disp = Gdk::Display::get_default();
    Glib::RefPtr<Gdk::Screen> scrn = disp->get_default_screen();
    Gdk::ModifierType mods;
    int xpos, ypos;

    disp->get_pointer(scrn, xpos, ypos, mods);
    printf("xpos = %d, ypos = %d\n", xpos, ypos);
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM