我编写了一个简单的代码,使用ncurses打印当前光标位置
#include <ncurses.h>
int main() {
initscr();
move(10,10);
int x,y;
getyx(stdscr,y,x);
printf("cursor position is x:%i y:%i",x,y );
}
我需要将该光标位置映射到以像素为单位的实际屏幕位置(而不是行/列),我想出了如何使用xdotool获取终端像素尺寸和位置,但是需要一种方法来找到光标位置。
答案 0 :(得分:0)
是因为您错误地使用了ncurses,所以在使用ncurses之前您需要了解很多概念,我建议您先阅读本教程页面http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html(简短版)和https://invisible-island.net/ncurses/ncurses-intro.html(大版本),库引用https://invisible-island.net/ncurses/man/ncurses.3x.html
但是我会在第一步中为您提供帮助:
#include <ncurses.h>
int main() {
int x,y;
initscr(); //first start the ncurses screen
move(10,10);
printw("cursor position is x:%i y:%i",x,y); //we use pritnw instead printf because we not use the std in/out
refresh(); //reflect all the modification of we made at stdscr (load into memory the stdscr data)
getch(); //char input to pause the program (use getch() instead getchar())
endscr(); //close the window, from here the std in/out enables again
}