[英]Execute function more than once while key is pressed (ncurses)
我希望能够在按右键时多次运行oasascript
execlp(...)
不能用 ncurses 模拟)。
程序编译并运行,但是当我按右键时,它会增加一次亮度然后中断。 我想让它继续运行,所以当再次按下右键以在按住键的同时重复操作时。
#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();
}
就其性质而言,您不能多次运行execlp()
,但可以将其替换为fork()
等。 但我的偏好是寻找直接的 API 解决方案来控制亮度,而不是启动单独的进程来伪造按键。 为此,我发现了这个: 在 Mac OS X 应用程序中调整屏幕亮度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.