I would like to be able to run the function execlp(...)
more than once when pressing the right key (this works only on mac, it basically uses oasascript
to press the corresponding key for increasing the brightness as I know these special keys can't be simulated with ncurses).
The program compiles and runs, but when I press the right key, it increases the brightness once then interrupts. I would like to keep it running so when the right key is pressed again to repeat the action while the key is kept pressed.
#include <ncurses.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int key = 0;
initscr();
noecho();
curs_set(TRUE);
keypad(stdscr, TRUE);
nodelay(stdscr, TRUE);
while(1) {
clear();
refresh();
key = getch();
if (key == KEY_RIGHT) {
execlp(
"osascript",
"osascript",
"-e",
"tell application \"System Events\" to key code 144 using {option down, shift down}",
NULL
);
}
}
endwin();
}