相关疑难解决方法(0)

在Linux上检查C ++中的按键

有没有一种简单的方法来检查是否按下了某个键,以便可以在线程中循环浏览?首选不要使用库,绝对不要使用ncurses。我在互联网上找不到能正常工作的东西。

c++ linux keypress

6
推荐指数
2
解决办法
4447
查看次数

使用 Xlib 获取鼠标点击坐标

我想知道如何使用 Xlib 在屏幕上的任何位置获取鼠标单击的 x 和 y 坐标。我发现这篇文章可以获取当前指针位置

如何获取当前鼠标(指针)在 X 中的位置坐标

但我不知道如何修改它,以便在单击鼠标时获取 xy 坐标。我试图编写这段代码,但它什么也没做。

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

int main (){
int x=-1,y=-1;
XEvent event;
int button;
Display *display = XOpenDisplay(NULL);
if (display == NULL) {
    fprintf(stderr, "Cannot connect to X server!\n");
    exit (EXIT_FAILURE);
}
Window root= XDefaultRootWindow(display);
XSelectInput(display, root, ButtonReleaseMask) ;
while(1){
XNextEvent(display,&event);
switch(event.type){
    case ButtonRelease:
        switch(event.xbutton.button){
            case Button1:
                x=event.xbutton.x;
                y=event.xbutton.y;
                button=Button1;
                break;

            case Button3:
                x=event.xbutton.x;
                y=event.xbutton.y;
                button=Button3;
                break;
            default:
                break;

        }
        break;
    default:
        break; …
Run Code Online (Sandbox Code Playgroud)

c x11 xlib

3
推荐指数
1
解决办法
9990
查看次数

标签 统计

c ×1

c++ ×1

keypress ×1

linux ×1

x11 ×1

xlib ×1