void keyboard_settypematics(uint8_t repeat_nchars, enum REPEAT_DELAYS repeat_delay) { uint8_t typematics_option = 0; ((typematic_options_t*) &typematics_option)->repeat_rate = set_repeat_rate(repeat_nchars); ((typematic_options_t*) &typematics_option)->repeat_delay = repeat_delay; keyboard_enc_send_cmd(KEYBOARD_ENC_CMD_AUTODELAY); keyboard_enc_send_cmd(typematics_option); }
int main(int argc, char **argv) { int c, error; int rflag, tflag, lflag, cflag, dflag, aflag, iflag, errflag, Dflag, Rflag, rtlacDRflag, sflag, bflag; char *copt, *aopt, *delay, *rate, *layout_name, *b_type, *freq_str; char *kbdname = KBD_DEVICE, *endptr = NULL; int kbd, freq_val; extern char *optarg; extern int optind; rflag = tflag = cflag = dflag = aflag = iflag = errflag = lflag = Dflag = Rflag = sflag = bflag = 0; copt = aopt = (char *)0; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); while ((c = getopt(argc, argv, "rtlisc:a:d:D:R:b:")) != EOF) { switch (c) { case 'r': rflag++; break; case 't': tflag++; break; case 'l': lflag++; break; case 'i': iflag++; break; case 's': sflag++; break; case 'c': copt = optarg; cflag++; break; case 'a': aopt = optarg; aflag++; break; case 'd': kbdname = optarg; dflag++; break; case 'D': delay = optarg; Dflag++; break; case 'R': rate = optarg; Rflag++; break; case 'b': bflag++; break; case '?': errflag++; break; } } /* * Check for valid arguments: * * If argument parsing failed or if there are left-over * command line arguments(except -s and -b option), * then we're done now. */ if (errflag != 0 || (sflag == 0 && bflag == 0 && argc != optind)) { usage(); exit(1); } /* * kbd requires that the user specify either "-i" or "-s" or "-b" or * at least one of -[rtlacDR]. The "-d" option is, well, optional. * We don't care if it's there or not. */ rtlacDRflag = rflag + tflag + lflag + aflag + cflag + Dflag + Rflag; if (!((iflag != 0 && sflag == 0 && bflag == 0 && rtlacDRflag == 0) || (iflag == 0 && sflag != 0 && bflag == 0 && dflag == 0 && rtlacDRflag == 0) || (iflag == 0 && sflag == 0 && bflag == 0 && rtlacDRflag != 0) || (iflag == 0 && sflag == 0 && bflag != 0 && rtlacDRflag == 0))) { usage(); exit(1); } if (Dflag && atoi(delay) <= 0) { (void) fprintf(stderr, "Invalid arguments: -D %s\n", delay); usage(); exit(1); } if (Rflag && atoi(rate) <= 0) { (void) fprintf(stderr, "Invalid arguments: -R %s\n", rate); usage(); exit(1); } /* * Open the keyboard device */ if ((kbd = open(kbdname, O_RDWR)) < 0) { perror("opening the keyboard"); (void) fprintf(stderr, "kbd: Cannot open %s\n", kbdname); exit(1); } if (iflag) { kbd_defaults(kbd); exit(0); /* A mutually exclusive option */ /*NOTREACHED*/ } if (tflag) (void) get_type(kbd); if (lflag) get_layout(kbd); if (cflag && (error = click(copt, kbd)) != 0) exit(error); if (rflag) reset(kbd); if (aflag && (error = abort_enable(aopt, kbd)) != 0) exit(error); if (Dflag && (error = set_repeat_delay(delay, kbd)) != 0) exit(error); if (Rflag && (error = set_repeat_rate(rate, kbd)) != 0) exit(error); if (sflag) { if (argc == optind) { layout_name = NULL; } else if (argc == (optind + 1)) { layout_name = argv[optind]; } else { usage(); exit(1); } if ((error = set_kbd_layout(kbd, layout_name)) != 0) exit(error); } if (bflag) { if (argc == optind) { b_type = "keyboard"; } else if (argc == (optind + 1)) { b_type = argv[argc - 2]; } else { usage(); exit(1); } if (strcmp(b_type, "keyboard") && strcmp(b_type, "console")) { usage(); exit(1); } freq_str = argv[argc - 1]; errno = 0; freq_val = (int)strtol(freq_str, &endptr, 10); if (errno != 0 || endptr[0] != '\0') { usage(); exit(1); } if (freq_val < 0 || freq_val > INT16_MAX) { (void) fprintf(stderr, "Invalid arguments: -b %s\n", freq_str); (void) fprintf(stderr, "Frequency range: [0 - %d]\n", INT16_MAX); exit(1); } if ((error = set_beep_freq(kbd, b_type, freq_val)) != 0) exit(1); } return (0); }