# Using the Keyboard

    #include <stdio.h>
    #include <string.h>
    #include "graphapp.h"

    Font *f = NULL;
    Point location = {0,0};

    void key_down(Control *c, unsigned long key)
    {
      char utf8[8];
      int width, max_width;

      max_width = get_control_area(c).width;

      unicode_char_to_utf8(key, utf8);
      width = font_width(f, utf8, strlen(utf8));
      if (location.x + width > max_width) {
        location.x = 0;
        location.y += font_height(f);
      }
      draw_utf8(g, location, utf8, strlen(utf8));
      location.x += width;
    }

    int main(int argc, char *argv[])
    {
      App *app;
      Window *w;
      Control *c;

      app = new_app(argc, argv);
      f = find_default_font(app);

      w = newwindow(app, rect(50,50,200,200),
                    "Press a Key", STANDARD_WINDOW);
      set_window_background(w, LIGHT_GREY);

      c = new_control(w, rect(10,10,180,180));
      on_control_key_down(c, key_down);

      show_window(w);
      main_loop(app);
      return 0;
    }

Notes:

- Keyboard call-back functions are sent an `unsigned long` Unicode character value.
- Various functions exist to translate Unicode to and from the UTF-8 encoding.
- UTF-8 strings are used when drawing text.
- There is a default font, which can be found using `find_default_font`.
- Fonts can be used to find the pixel size of strings drawn using that font.