keyboard 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. .TH KEYBOARD 2
  2. .SH NAME
  3. initkeyboard, ctlkeyboard, closekeyboard \- keyboard control
  4. .SH SYNOPSIS
  5. .nf
  6. .B
  7. #include <u.h>
  8. .B
  9. #include <libc.h>
  10. .B
  11. #include <thread.h>
  12. .B
  13. #include <keyboard.h>
  14. .PP
  15. .B
  16. Keyboardctl *initkeyboard(char *file)
  17. .PP
  18. .B
  19. int ctlkeyboard(Keyboardctl *kc, char *msg)
  20. .PP
  21. .B
  22. void closekeyboard(Keyboard *kc)
  23. .SH DESCRIPTION
  24. These functions access and control a keyboard interface
  25. for character-at-a-time I/O in a multi-threaded environment, usually in combination with
  26. .IR mouse (2).
  27. They use the message-passing
  28. .B Channel
  29. interface in the threads library
  30. (see
  31. .IR thread (2));
  32. programs that wish a more event-driven, single-threaded approach should use
  33. .IR event (2).
  34. .PP
  35. .I Initkeyboard
  36. opens a connection to the keyboard and returns a
  37. .B Keyboardctl
  38. structure:
  39. .IP
  40. .EX
  41. .ta 6n +\w'Channel 'u +\w'consfd; 'u
  42. typedef struct Keyboardct Keyboardctl;
  43. struct Keyboardctl
  44. {
  45. Channel *c; /* chan(Rune[20]) */
  46. char *file;
  47. int consfd; /* to cons file */
  48. int ctlfd; /* to ctl file */
  49. int pid; /* of worker proc */
  50. };
  51. .EE
  52. .PP
  53. The argument to
  54. .I initkeyboard
  55. is a
  56. .I file
  57. naming the device file from which characters may be read,
  58. typically
  59. .BR /dev/cons .
  60. If
  61. .I file
  62. is nil,
  63. .B /dev/cons
  64. is assumed.
  65. .PP
  66. Once the
  67. .B Keyboardctl
  68. is set up a
  69. message containing a
  70. .BR Rune
  71. will be sent on the
  72. .B Channel
  73. .B Keyboardctl.c
  74. to report each character read from the device.
  75. .PP
  76. .I Ctlkeyboard
  77. is used to set the state of the interface, typically to turn raw mode on and off
  78. (see
  79. .IR cons (3)).
  80. It writes the string
  81. .I msg
  82. to the control file associated with the device, which is assumed to be the regular device file name
  83. with the string
  84. .B ctl
  85. appended.
  86. .PP
  87. .I Closekeyboard
  88. closes the file descriptors associated with the keyboard, kills the worker processes,
  89. and frees the
  90. .B Keyboardctl
  91. structure.
  92. .PP
  93. .SH SOURCE
  94. .B /sys/src/libdraw
  95. .SH SEE ALSO
  96. .IR graphics (2),
  97. .IR draw (2),
  98. .IR event (2),
  99. .IR thread (2).
  100. .SH BUGS
  101. Because the interface delivers complete runes,
  102. there is no way to report lesser actions such as
  103. shift keys or even individual bytes.