gpt4 book ai didi

c - C 中的简单 NCURSES 鼠标处理

转载 作者:太空宇宙 更新时间:2023-11-04 03:46:57 25 4
gpt4 key购买 nike

我有以下代码:

#include <ncurses.h>
#include <string.h>

int
main()
{
int ch;

initscr();
noecho();
cbreak();
refresh();

while(1)
{
ch = getch();
addch(ch);
};

return 0;
}

它应该在按下鼠标按钮时在屏幕上输出一些东西,但实际上没有。

我尝试了修复 Mouse movement events in NCurses 的技巧没有成功。

此外,当我在同一个终端中运行 htop 时,鼠标点击也能正常工作。而且 htop 似乎没有做任何不同的事情,是吗? https://github.com/hishamhm/htop/search?q=MOUSE&ref=cmdform

最佳答案

我添加了 mousemask,现在可以使用了。

#include <ncurses.h>
#include <string.h>

int
main()
{
int ch;

initscr();
noecho();
cbreak();
refresh();
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);

while(1)
{
ch = getch();
addch(ch);
};

return 0;
}

关于c - C 中的简单 NCURSES 鼠标处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23521139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com