A key component of applications is user input. So far, console windows have handled keyboard input automatically. For graphical applications, we will have to define how our program responds to either the keyboard or mouse (the primary input devices for most computers are the keyboard and mouse which is what we use here but an input device can be anything from a joystick to a gaming console. Every programming language handles user input slightly differently although there are a few key similarities shared by all. Recall the framework for our graphical applications:
program Workspace;
uses FTGraphics;

procedure Initialize;
begin

end;

procedure OnEnterFrame;
begin

end;

begin
  RunGraphicalApp(@Initialize,@OnEnterFrame);
end.
We mentioned earlier that RunGraphicalApp contains a message loop that runs until the program exits. When a keystroke or mouse movement occurs the operating system (Windows, Mac OSX, Linux, etc) broadcasts messages to the currently focused window. The focused window is generally the foremost window often with a title bar that has a different color than other windows. The application's message loop then does some processing on this message. Up to this point, essentially all programming languages and applications handle keyboard and mouse inputs in the identical way: a message loop. To simplify matters (so that you don't have to worry about message loops), the FTGraphics library pays attention to the message loop in RunGraphicalApp and fills two variables Keyboard and Mouse with information pertaining to the current state of the keyboard and mouse. The following are the definitions of these two variables (note that they use programming constructs such as records and arrays which we have not yet discussed but will cover in more detail later).
type
  TKeyState = record
    Press : Boolean;
    Down : Boolean;
  end;
  TKeyboardInput = Array[0..255] of TKeyState;
  TMouseState = record
    Click : Boolean;
    Down : Boolean;
  end;
  TMouseInput = record
    Left : TMouseState;
    Right : TMouseState;
  end;

var
  Keyboard : TKeyboard;
  Mouse : TMouse;
Let's first look at the mouse. You will notice that the Mouse variable is a record which has two fields: Left and Right. These of course correspond to the left and right mouse buttons. Left and Right are themselves records which have fields Click and Down. Click and Down are Boolean variables. The mouse variable is refreshed at the beginning of each frame. If Click is True it means that the mouse button was pressed at least once before the start of the frame. If Down is True it means that mouse button was still being held at the start of the frame. The easiest way to understand this is with example code. Try running the following in the Workspace project. Click and hold the left and right buttons interchangeably for a few seconds.
program Workspace;
uses FTGraphics;

procedure Initialize;
begin
end;

procedure OnEnterFrame;
begin
  SetFont('Arial',clRed,36);

  if Mouse.Left.Down then
    TextOut(0,0,'The "Left" mouse button is down.')
  else if Mouse.Right.Down then
    TextOut(0,0,'The "Right" mouse button is down.');
end;

begin
  RunGraphicalApp(@Initialize,@OnEnterFrame);
end.
You will see that when Mouse.Left.Down is True, the string 'The "Left" mouse button is down.' is displayed. As you probably already inferred, the dot ( . ) is used to reference fields in a record. Try changing Down to Click and observe the difference in the program's behavior. You will notice that Click is True only for a single frame no matter how long you hold the mouse button down.

The Keyboard variable is an array of all possible keys that could be pressed. Each key's state is represented by the TKeyState record which contains two boolean fields Press and Down. The difference between these Press and Down is similar to the difference between Click and Down for the mouse buttons.
Excercise 2-13.
Write code for the following problems.
  1. Draw ClickCount = 0 to the screen. Next display the total number of clicks from the left mouse button by changing this text on every click. (Hint: To do this you will need to use one of the string functions from Section 2.7)
  2. Display the line 'The "A" key is down.' when they A key is held. Hint: All alphabetic keys are indexed by their ASCII code (i.e. you can use Ord('A') to determine the index of the A key).
  3.   First, turn the grid on using GridVisible in Initialize. Next, display a unit circle (a circle of radius 1) that starts at the center of the screen and moves 1 unit in any direction based on whether the left, right, up, or down arrow keys are pressed. Hint: Non-alphanumeric keys have "virtual key codes." These indices for the arrow keys are defined in FTGraphics as VK_LEFT, VK_RIGHT, VK_UP, and VK_DOWN. Keep in mind, the position of the circle can be kept track of with variables.