Tag: keypress

用于Ubuntu 14.04的C中的UINPUT设备程序不起作用。 为什么? 第2部分:

我正在使用Ubuntu 14.04,我在c中设置了一个虚拟键盘,这需要输入才能工作。 我的程序应该将密钥’a’发送到终端,就像我按下键盘上的’a’键一样。 这是我的源代码: int main() { int uinp_fd; int i; /********** Open uinput file section. **********************/ uinp_fd = open(“/dev/uinput”, O_WRONLY|O_NDELAY); if(uinp_fd < 0) { printf("Unable to open /dev/uinput\n"); return -1; } else printf("Can open /dev/uinput\n"); /********* Setup input device structure section: ***********/ memset(&uinp,0,sizeof(uinp)); snprintf(uinp.name, UINPUT_MAX_NAME_SIZE, "The C Keyboard"); uinp.id.bustype = BUS_USB; uinp.id.version = 1; […]

等待在循环中按C键进入?

我正在写一个C程序,我需要等待用户按任意键才能继续。 当我使用getchar(); 它等待按下Enter键。 但是当我在while循环中使用它while ,它不起作用。 如何使我的代码等待按任何键继续循环? 这是我的代码示例。 我正在使用GNU / Linux。 #include #include int main() { int choice; while(1) { printf(“1.Create Train\n”); printf(“2.Display Train\n”); printf(“3.Insert Bogie into Train\n”); printf(“4.Remove Bogie from Train\n”); printf(“5.Search Bogie into Train\n”); printf(“6.Reverse the Train\n”); printf(“7.Exit”); printf(“\nEnter Your choice : “); fflush(stdin); scanf(“%d”,&choice); switch(choice) { case 1: printf(“Train Created.”); break; case 2: […]