Advertisement
okpalan

pointer.c

May 5th, 2024 (edited)
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. // gcc -o pointer pointer.c -static -lncurses -DNCURSES_STATIC
  2. #include <ncurses.h>
  3.  
  4. int main() {
  5.     // Initialize ncurses
  6.     initscr();
  7.     cbreak(); // Line buffering disabled
  8.     noecho(); // Don't echo user input
  9.     keypad(stdscr, TRUE); // Enable keypad mode
  10.  
  11.     // Enable mouse events
  12.     mousemask(ALL_MOUSE_EVENTS, NULL);
  13.    
  14.     // Print instructions
  15.     mvprintw(0, 0, "Move the mouse around the terminal window...");
  16.  
  17.     // Track mouse events
  18.     while (1) {
  19.         int ch = getch();
  20.         if (ch == KEY_MOUSE) {
  21.             MEVENT event;
  22.             if (getmouse(&event) == OK) {
  23.                 // Print mouse event information
  24.                 mvprintw(2, 0, "Mouse event at (%d, %d)", event.x, event.y);
  25.                 refresh();
  26.             }
  27.         }
  28.         // Exit on 'q' key press
  29.         if (ch == 'q')
  30.             break;
  31.     }
  32.  
  33.     // Cleanup
  34.     endwin();
  35.  
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement