如何使用Ncurses在屏幕坐标中找到光标位置?

问题描述 投票:0回答:1

我编写了一个简单的代码,使用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获取终端像素尺寸和位置,但是需要一种方法来找到光标位置。

c linux ncurses xdotool
1个回答
0
投票

是因为您使用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
}
© www.soinside.com 2019 - 2024. All rights reserved.