3 <title>VNC server for eCos</title>
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
7 <body bgcolor="#FFFFFF">
8 <h1>VNC server for eCos</h1>
10 <p>VNC stands for Virtual Network Computing. It is in essence, a remote display
11 system which allows you to view a computing 'desktop' environment not only on
12 the machine where it is running, but from anywhere on the Internet and from
13 a wide variety of machine architectures. For full details of VNC, and to get
14 the vncviewer program see: <a href="http://www.uk.research.att.com/vnc/" target="VNC_PAGE">http://www.uk.research.att.com/vnc/</a>.
16 <p>The VNC server for eCos runs on the target platform and waits for a client
17 (vncviewer program running on a PC) to connect via an ethernet connection (port
18 5900). Once a client has connected, the target platform has a virtual screen,
19 keyboard and mouse.</p>
22 <p>The eCos port of the VNC server has been designed with some limitations in
23 order to keep memory and processor power requirements to a minimum.</p>
25 <li>The VNC client must accept the settings that the VNC server suggests (bits-per-pixel,
26 number-of-colours and so on as specified at build time with the eCos configuration
27 tool) or the VNC server will just disconnect.</li>
28 <li>The VNC server only supports CoRRE encoding and RAW encoding for sending
29 display data to the client.</li>
30 <li>The VNC server does not support password authentication, the client is able
31 to connect without the user typing in a password.</li>
32 <li>Only one VNC client may connect to the VNC server at a time.</li>
34 <p>In reality these limitations are not a problem.</p>
36 <h2>VNC server API</h2>
37 <p>If the VNC server is to be used with the eCos port of MicroWindows, then VNC
38 server API may be ignored and the application should just use one of the API
39 supplied by MicroWindows.</p>
40 <h3>VNC server display API</h3>
41 <p>To use the VNC server display API the application should include the VNC server
42 header file by adding the following line to their C application:</p>
43 <p><font face="Courier New, Courier, mono"><font size="-1">#include <vnc-server.h>
44 /* VNC server header file *</font></font></p>
45 <p>This file specifies several function to manipulate the display.</p>
46 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
49 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><b>vnc_frame_forma</b></font><b><font face="Courier New, Courier, mono">t_t*
50 VncGetInfo(void)</font></b></font></p>
51 <p>The VNC get info function returns a pointer to a 'vnc_frame_format_t'
52 type structure and is used to get information about the VNC display. 'vnc_frame_format_t'
53 is defined in the vnc-server.h file as:</p>
54 <p><font face="Courier New, Courier, mono" size="-1">typedef struct<br>
56 cyg_uint16 frame_width;<br>
57 cyg_uint16 frame_height;<br>
58 void * frame_buffer;<br>
59 bool rgb332;<br>
60 </font><font face="Courier New, Courier, mono" size="-1">bool
62 bool rgb565;<br>
63 </font><font face="Courier New, Courier, mono" size="-1">bool
65 } vnc_frame_format_t;</font></p>
66 <p>The frame_width and frame height fields contain the VNC server display
68 <p>The * frame_buffer pointer contains the address of the actual frame buffer
69 the VNC server uses, though the application should never write to this
71 <p>The final 4 (bool) fields specifiy the pixel format - only one of them
72 will be set to true.</p>
76 <p> </p><table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
79 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b><font face="Courier New, Courier, mono">void
80 VncInit(vnc_colour_t colour)</font></b></font></p>
81 <p>The VNC initialise function, initialises the VNC server and paints the
82 display with the specified colour. This funcftion must be called before
83 any of the other VNC server display functions are used, except for VncGetInfo()
84 - which may be called at any time.</p>
85 <p>The type 'vnc_colour_t' is defined in the vnc-server.h file - and is
86 used to represent a colour. If the VNC server is built to support 8-bit
87 pixel data then 'vnc_colour_t' will be type cyg_uint8, but if 16-bit pixel
88 data is being used then 'vnc_colour_t' will be type cyg_uint16.</p>
93 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
96 <p><font face="Courier New, Courier, mono"><b><font face="Courier New, Courier, mono">void
97 VncDrawPixel(cyg_uint16 x,<br>
98 cyg_uint16
100
101 vnc_colour_t colour)</font></b><font face="Courier New, Courier, mono"></font></font></p>
102 <p>The VNC draw pixel function simply draws a pixel of colour, 'colour',
103 at position ('x', 'y') on the VNC server display. Note that pixel (0,
104 0) is the top-left pixel in the display.</p>
109 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
112 <p><font face="Courier New, Courier, mono"><b><font face="Courier New, Courier, mono">vnc_colour_t
113 VncReadPixel(cyg_uint16 x<br>
114
115 cyg_uint16 y)</font></b></font></p>
116 <p>The VNC read pixel function simply returns the colour of the pixel at
117 position ('x', 'y') on the VNC server display. Note that pixel (0, 0)
118 is the top-left pixel in the display.</p>
122 <p> </p><table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
125 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b>void
126 VncDrawHorzLine(cyg_uint16 x1,<br>
127
129
131
132 vnc_colour_t colour)</b></font></p>
133 <p>The VNC draw horizontal line function simply draws a line of pixels of
134 colour, 'colour', from position ('x1', 'y') to position ('x2', 'y') (inclusive)
135 on the VNC server display. Note that pixel (0, 0) is the top-left pixel
141 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
144 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b><font face="Courier New, Courier, mono">void
145 VncDrawVertLine(cyg_uint16 x,<br>
146
148
150
151 vnc_colour_t colour)</font></b></font></p>
152 <p>The VNC draw vertical line function simply draws a line of pixels of
153 colour, 'colour', from position ('x', 'y1') to position ('x', 'y2') (inclusive)
154 on the VNC server display. Note that pixel (0, 0) is the top-left pixel
160 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
163 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b><font face="Courier New, Courier, mono">void
164 VncFillRect(cyg_uint16 x1,<br>
165
167
169
171
172 vnc_colour_t colour)</font></b></font></p>
173 <p>The VNC fill rectangle function draws a solid rectangle of colour, 'colour',
174 with top-left corner at ('x1', 'y1') and bottom right corner at ('x2',
175 'y2') (inclusive) on the VNC server display. Note that pixel (0, 0) is
176 the top-left pixel in the display.</p>
181 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
184 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b>void
185 VncCopyRect(cyg_uint16 x1,<br>
186
188
189 cyg_uint16 width, <br>
190
191 cyg_uint16 height,<br>
192
194
195 cyg_uint16 y2)</b></font></p>
196 <p>The VNC copy rectangle function copies a rectangle from one part of the
197 VNC display to another. The source rectangle is of width 'width', and
198 height 'height', with its top-left corner at ('x1', 'y1'). The destination
199 rectangle is the same size with its top-left corner at ('x2', 'y2'). Note
200 that pixel (0, 0) is the top-left pixel in the display.</p>
205 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
208 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b>void
209 VncCopyRect2Buffer(cyg_uint16 x,<br>
210
212
213 cyg_uint16 width,<br>
214
215 cyg_uint16 height,<br>
216
218
219 cyg_uint16 buff_w,<br>
220
221 cyg_uint16 buff_h,<br>
222
223 cyg_uint16 x_off,<br>
224
225 cyg_uint16 y_off)</b></font></p>
226 <p>The VNC copy rectangle to buffer function copies a rectangle of the VNC
227 server display to a buffer supplied by the application. This function
228 is useful for saving areas of the display which will need to be restored
229 later, such as the area under a mouse cursor.</p>
230 <p>The rectangle of the display to be copied is of width 'width' and height
231 'height' with its top-left corner at position ('x', 'y'). The address
232 of the buffer supplied to copy the image data is specified by '*buffer'.
233 This buffer is of width 'buff_w' and height 'buff_height'. If the buffer
234 width and height is larger than the rectangle being copied from the display,
235 an x and y offset may be supplied ('x_off' and 'y_off' respectively) to
236 offset where the rectangle of display data in the buffer.</p>
237 <p>For example a buffer of width = 50 and height = 40 could be defined with:</p>
238 <p><font face="Courier New, Courier, mono"><font size="-1">vnc_colour_t
239 my_buffer[40][50];</font></font></p>
240 <p>Then VncCopyRect2Buffer() could be called with:</p>
241 <p><font face="Courier New, Courier, mono"><font size="-1">VncCopyRect2Buffer(10,
242 /* x-pos on display */<br>
243 10,
244 /* y-pos on display */</font></font><br>
245 <font face="Courier New, Courier, mono"><font size="-1"> 30,
246 /* rectangle width on display */</font></font> <br>
247 <font face="Courier New, Courier, mono"><font size="-1"> 20,
248 /* rectangle heigth on display */</font></font> <br>
249 <font face="Courier New, Courier, mono"><font size="-1">(void
250 *)my_buffer, /* Address of buffer */<br>
251 </font><font face="Courier New, Courier, mono"><font size="-1"> 50,
252 /* buffer width */</font></font> <font size="-1"> <br>
253 </font><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font size="-1"> 40,
254 /* buffer height */</font></font> <br>
255 </font></font><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font size="-1"> 5,
256 /* buffer x-offset */</font></font> <font size="-1"> <br>
257 </font><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font size="-1"> 6);
258 /* buffer y-offset */</font></font> <font size="-1"> </font></font><font size="-1">
260 </font></font></font></p>
261 <p>This would copy a 30 pixel wide, 20 pixel high rectangle from (10, 10)
262 of the VNC server display to the buffer 'my_buffer'. Inside the buffer
263 there would by an x-offset of 5 and a y offset of 6. Thus pixel (10, 10)
264 from the VNC server display would now be copied to my_buffer[6][5] - and
265 so on for the rest of the rectangle.</p>
270 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
273 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b>void
274 VncCopyBuffer2Rect(void *buffer,<br>
275
276 cyg_uint16 buff_w,<br>
277
278 cyg_uint16 buff_h, <br>
279
280 cyg_uint16 x_off,<br>
281
282 cyg_uint16 y_off,<br>
283
285
287
288 cyg_uint16 width,<br>
289
290 cyg_uint16 height)</b></font></p>
291 <p>The VNC copy buffer to rectangle function copies a rectangle from a buffer
292 supplied by the application to the VNC server display. This function is
293 usefull for restoring previously saved areas of the display.</p>
294 <p>For example, to restore the rectangle saved in the previous example use
295 of the VncCopyRect2Buffer() function above, the VncCopyBuff2Rect() would
297 <p><font face="Courier New, Courier, mono"><font size="-1">VncCopyBuffer2Rect(</font><font face="Courier New, Courier, mono"><font size="-1">(void
298 *)my_buffer, /* Address of buffer */</font></font><font size="-1"><br>
299 </font><font face="Courier New, Courier, mono"><font size="-1"> 50,
300 /* buffer width */</font></font> <font size="-1"> <br>
301 </font><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font size="-1"> 40,
302 /* buffer height */</font></font> <br>
303 </font></font><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font size="-1"> 5,
304 /* buffer x-offset */</font></font> <font size="-1"> <br>
305 </font><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"><font size="-1"> 6,
306 /* buffer y-offset */</font></font> <font size="-1"> </font></font><br>
307 </font></font><font face="Courier New, Courier, mono"><font size="-1"> 10,
308 /* x-pos on display */<br>
309 10,
310 /* y-pos on display */</font></font><br>
311 <font face="Courier New, Courier, mono"><font size="-1"> 30,
312 /* rectangle width on display */</font></font> <br>
313 <font face="Courier New, Courier, mono"><font size="-1"> 20);
314 /* rectangle heigth on display */</font></font> </p>
315 <p>Note that in most uses of the VncCopyBuff2Rect() and VncCopyRect2Buffer()
316 functions would be called with:<br>
317 width = buff_w<br>
318 heigth = buff_h<br>
319 x_off = 0<br>
320 y_off = 0.</p>
321 <p>In this case there is no offset into the buffer and the buffer is used
322 100% to store the rectangle from the display. <font face="Courier New, Courier, mono"><font size="-1">
327 <p> </p><table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
330 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b>void
331 VncCopyBuffer2RectMask(void *buffer,<br>
332
333 cyg_uint16 buff_w,<br>
334
335 cyg_uint16 buff_h, <br>
336
337 cyg_uint16 x_off,<br>
338
339 cyg_uint16 y_off,<br>
340
342
344
345 cyg_uint16 width,<br>
346
347 cyg_uint16 height,<br>
348 <font face="Courier New, Courier, mono"> vnc_colour_t
349 mask_colour</font> )</b></font></p>
350 <p>The VNC copy buffer to rectangle with mask function works exactly like
351 VncCopyRect2Buffer(), except that a mask colour is also specified. Any
352 pixels in the buffer that have the value mask_colour, will not be copied
353 to the frame buffer - leaving the original pixels untouched.<font face="Courier New, Courier, mono"><font size="-1">
359 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
362 <p><font face="Courier New, Courier, mono"><font face="Courier New, Courier, mono"></font><b>vnc_printf_return_t
363 VncPrintf(MWCFONT* font,<br>
364 </b></font><font face="Courier New, Courier, mono"><b> int
366 vnc_colour_t
368 int
370 int
372 const
373 char *fmt, ... );)</b></font></p>
374 <p>The VNC printf function writes test to a specified position in the VNC
375 frame buffer, using the specified font and colour.</p>
376 <p>The '* font' argument is a pointer to a MWCFONT font structure. This
377 is the same font structure as used by MicroWindows, though the VNC server
378 has its own copy of the font description files. The available fonts are:</p>
379 <p> font_rom8x16<br>
380 font_rom8x8<br>
381 font_winFreeSansSerif11x13<br>
382 font_winFreeSystem14x16<br>
383 font_helvB10<br>
384 font_helvB12<br>
385 font_helvR10<br>
386 font_X5x7<br>
387 font_X6x13</p>
388 <p>If the font argument is set to '0', then the default font (winFreeSystem14x16)
390 <p>The 'do_print' argument is used to specify whether the function should
391 actually write the text to the frame buffer. If do_print is non-zero,
392 then the text will be written to the frame buffer. If do_print is zero,
393 then no text will be written, but the return value from the function will
395 <p>The 'colour' argument specifies the colour to use to write the text.</p>
396 <p>The 'x' and 'y' arguments specify the pixel position (x, y) in the frame
397 buffer of the top left pixel of the first character to be printed.</p>
398 <p>The 'const char *fmt, ...' argumets are used as in a normal printf statement.</p>
399 <p>The function returns a data structure of type vnc_printf_return_t, this
401 <p> typedef struct<br>
402 {<br>
403 int chars;<br>
404 cyg_uint16 width;<br>
405 cyg_uint16 height;<br>
406 } vnc_printf_return_t;</p>
407 <p>The 'chars' values is exactly as would have been returned by the printf()
409 <p>The width and height attributes specify the width and height of a rectangle
410 surrounding the text written to the screen. This data can be used to know
411 how much of the frame buffer needs to be painted to delete the text, or
412 (used together with the 'do_print' argument set to 0) to calculate how
413 much of the screen should be saved before printing to it so that it may
414 be restored later.</p>
415 <p>An example of writing some text to position (250, 200) of the frame buffer,
416 using the colout cyan and the font, winFreeSansSerif11x13:</p>
417 <p><font face="Courier New, Courier, mono"></font><font face="Courier New, Courier, mono"><font size="-1">vnc_printf_return_t
418 print_area;</font></font></p>
419 <p><font face="Courier New, Courier, mono"><font size="-1">print_area =
420 VncPrintf(&font_winFreeSansSerif11x13,<br>
421 1,<br>
422 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font><font size="-1">
424 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font><font size="-1">
426 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font><font size="-1">
428 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font><font size="-1">
429 </font></font><font face="Courier New, Courier, mono"><font size="-1">"Hello
430 World!\nUsing winFreeSansSerif11x13 font");</font></font></p>
431 <p>Note: 'print_area.width' and 'print_area.height' will be set to indicate
432 how much of the frame buffer was used to print this text.</p>
433 <p>Another example, using the default font this time:</p>
434 <p><font face="Courier New, Courier, mono"><font size="-1">print_area =
436 1,<br>
437 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font><font size="-1">VNC_BLACK,
439 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font><font size="-1">250,<br>
440 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font><font size="-1">200,<br>
441 </font><font face="Courier New, Courier, mono"><font size="-1"> </font></font></font><font face="Courier New, Courier, mono"><font size="-1">"50
442 * 34 = %d", 50*34);</font></font></p>
447 <p>Also included in the vnc-server.h header file are 16 predefined colours:</p>
448 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
450 <td><font face="Courier New, Courier, mono"><b>VNC_BLACK<br>
458 VNC_LTGREY /* Same as VNC_LTGRAY */<br>
460 VNC_GREY /* Same as VNC_GRAY */<br>
468 <p>These colours are all of type vnc_colour_t and are always correct for the selected
473 <p>Also contained in the vnc-server.h header file is a macro to convert from a
474 full RGB colour value to the nearest colour that the type vnc_colour_t can represent.
476 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
479 <p><font face="Courier New, Courier, mono"><b>VNC_RGB2COL(red, green, blue)</b></font></p>
480 <p>The arguments red, green and blue each have a value from 0 to 255.</p>
481 <p>For example, to initialise the VNC server display with a colour as close
482 to a very specific shade of green [red=156, green=229, blue=91] - the
483 VncInit() function could be called as follows:</p>
484 <p><font face="Courier New, Courier, mono" size="-1">VncInit( VNC_RGB2COL(156,
485 229, 91) );</font></p>
486 <p>Obviously the colour match will be better if the VNC server had been
487 built with 16 bits per pixel rather than with 8 bits per pixel, but in
488 each case the best available colour will be used.</p>
492 <p>Though not strictly a display function, a function to sound a bell on the client
494 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
497 <p><font face="Courier New, Courier, mono"><b><font face="Courier New, Courier, mono">void
498 VncSoundBell(void)</font></b></font></p>
499 <p>The VNC Sound Bell function simply sounds a bell on the client - if the
500 client supports this.</p>
505 <h3>VNC server mouse API</h3>
506 <p>The VNC server mouse device driver is a standard eCos IO device driver. The
507 device name is "/dev/vnc_mouse" by default, but this may be modified
508 with the configuration tool. The first step in using the mouse device driver
509 is to use the cyg_io_lookup() function:</p>
510 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
513 <p> <font face="Courier New, Courier, mono" size="-1">Cyg_ErrNo mouse_err;<br>
514 cyg_io_handle_t mouse_handle;<br>
515 cyg_uint8 mouse_data[8];<br>
516 cyg_uint32 mouse_len;</font><br>
518 <font face="Courier New, Courier, mono" size="-1">mouse_err = cyg_io_lookup("/dev/vnc_mouse",
519 &mouse_handle); /* Open mouse device */ if (mouse_err == -ENOENT)<br>
521 diag_printf("Could not open mouse device\n");
527 <p>Once the cyg_io_lookup() function has found the mouse device driver, the driver
528 is active and should be read regularly to prevent the receive buffer from overflowing
529 with data. Data is read using the cyg_io_read() function:</p>
530 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
533 <p><font face="Courier New, Courier, mono" size="-1">mouse_len = 8; /*
534 Try to read 8 bytes from mouse */ <br>
535 cyg_io_read(mouse_handle, mouse_data, &mouse_len ); <br>
536 if (mouse_len == 0)<br>
538 diag_printf("Mouse has no new data\n");<br>
542 diag_printf("Have New mouse data:\n");</font><br>
543 <font face="Courier New, Courier, mono" size="-1"> <font face="Courier New, Courier, mono" size="-1">diag_printf(" Mouse
544 button data: 0x%x\n", mouse_data[1]);</font> </font> <br>
545 <font face="Courier New, Courier, mono" size="-1">diag_printf(" Mouse
546 x-coord: %d\n", mouse_data[2]*256 + mouse_data[3]);</font><br>
547 <font face="Courier New, Courier, mono" size="-1">diag_printf(" Mouse
548 y-coord: %d\n", mouse_data[4]*256 + mouse_data[5]);<br>
553 <p>The cyg_io_read() function is a non-blocking function and each mouse event
554 generates 8 bytes of data:</p>
555 <p>Byte 0: Padding - always zero<br>
556 Byte 1: Button data (bit 0 = 1 if the left button is pressed, bit 2 = 1 if the
557 right button is pressed)<br>
558 Byte 2: Mose position x-coord MSB<br>
559 Byte 3: Mose position x-coord LSB<br>
560 Byte 4: Mose position y-coord MSB<br>
561 Byte 5: Mose position y-coord LSB<br>
562 Byte 6: Padding - always zero<br>
563 Byte 7: Padding - always zero </p>
565 <h3>VNC server keyboard API</h3>
566 <p>The VNC server keyboard device driver is a standard eCos IO device driver.
567 The device name is "/dev/vnc_kbd" by default, but this may be modified
568 with the configuration tool. The first step in using the keyboard device driver
569 is to use the cyg_io_lookup() function:</p>
570 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
573 <p> <font face="Courier New, Courier, mono" size="-1">Cyg_ErrNo kdb_err;<br>
574 cyg_io_handle_t kbd_handle;<br>
575 cyg_uint8 kbd_data[8];<br>
576 cyg_uint32 kbd_len;</font><br>
578 <font face="Courier New, Courier, mono" size="-1">kbd_err = cyg_io_lookup("/dev/vnc_kbd",
579 &kbd_handle); /* Open kbd device */ <br>
580 if (kbd_err == -ENOENT)<br>
582 diag_printf("Could not open kbd device\n"); <br>
587 <p>Once the cyg_io_lookup() function has found the keyboard device driver, the
588 driver is active and should be read regularly to prevent the receive buffer
589 from overflowing with data. Data is read using the cyg_io_read() function:</p>
590 <table width="91%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
593 <p><font face="Courier New, Courier, mono" size="-1">kbd_len = 4; /*
594 Try to read 4 bytes from keyboard */ <br>
595 cyg_io_read(kbd_handle, kbd_data, &kbd_len ); <br>
596 if (kbd_len == 0)<br>
598 diag_printf("Keyboard has no new data\n");<br>
602 diag_printf("Have New keyboard data:\n");<br>
603 if (kbd_data[1])<br>
604 { </font><br>
605 <font face="Courier New, Courier, mono" size="-1"><font face="Courier New, Courier, mono" size="-1"> diag_printf(" Keysym
606 value 0x%x pressed\n",<br>
607 kbd_data[2]*256
608 + kbd_data[3]</font></font><font face="Courier New, Courier, mono" size="-1"><font face="Courier New, Courier, mono" size="-1">);<br>
609 }<br>
610 else<br>
611 {<br>
612 <font face="Courier New, Courier, mono" size="-1"> diag_printf(" Keysym
613 value 0x%x released\n",<br>
614 kbd_data[2]*256
615 + kbd_data[3]</font></font><font face="Courier New, Courier, mono" size="-1"><font face="Courier New, Courier, mono" size="-1">);</font></font><font face="Courier New, Courier, mono" size="-1">
617 } </font></font><br>
618 <font face="Courier New, Courier, mono" size="-1">}</font> </p>
622 <p>The cyg_io_read() function is a non-blocking function and each keystroke event
623 generates 4 bytes of data:</p>
624 <p>Byte 0: Padding - always zero<br>
625 Byte 1: Key pressed/released (1 when key pressed)<br>
626 Byte 2: Keysym value for key MSB<br>
627 Byte 3: Keysym value for key LSB<br>
629 <p>The actual key values are specified using the "keysym" values defined
630 by the X Window System. For most ordinary keys the keysym value is the same
631 as the corresponding ASCII value. For full details see either the Xlib Reference
632 Manual, published by O'Reilly & Associates or see the header file <X11/keysymdef.h>
633 from any X Window System installation (a google search for 'keysymdef.h' should