Class Programs and Activities

Keyboard input

1. Write a program to create a window. Give the window the focus. (Draw something in the window or leave it blank. It is not required.)

  1. type a key on the keyboard
  2. print the key value on the terminal
  3. loop (rinse and repeat)

Select one of the keys or be the "exit" key. Exit the program if this key is pressed. (Start with 'q' as the exit key.)

Note: The window must have the focus to receive key strokes. Try putting the focus on another window and see what happens.

2. What is the difference between "getKey()" and "checkKey()".

3. Draw a circle or other graphics object in the window. Use the arrow keys to move it around in the window. Use the "q" or "Q" key to exit the program.