DEFINITION Input; (* portable, except where noted *)

(*
Module Input is responsible for event timing, mouse and keyboard input.
*)

 CONST
  TimeUnit = 1000; (* portable, but VAR on other ports *) (* timer ticks per
second (platform dependent). *)
  SHIFT = 0; CTRL = 1; ALT = 2; (* for KeyState *)

 TYPE
  PollMouse = PROCEDURE (VAR keys: SET; VAR dx, dy, dz: INTEGER): BOOLEAN; (*
non-portable *)
  PollKeyboard = PROCEDURE (VAR ch: CHAR; VAR keys: SET): BOOLEAN; (* non-portable
*)

(* Returns the number of keystrokes in the keyboard input buffer. *)
 PROCEDURE Available (): INTEGER;

(* Reads the current mouse position x, y and the key state of the mouse buttons

(also called keys). The mouse buttons are numbered from the right to the left
as 
0, 1, 2 (i.e. 1 is the middle mouse button). For example, when the left and
middle 
buttons are pressed, keys will be set to {1, 2}. *)
 PROCEDURE Mouse (VAR keys: SET; VAR x, y: INTEGER);

(* Read a character from the keyboard buffer. Blocks if no character is available.
*)
 PROCEDURE Read (VAR ch: CHAR);

(* Returns the elapsed number of timer ticks from Oberon startup. *)
 PROCEDURE Time (): LONGINT;

(* Return the state of the shift keys. *)
 PROCEDURE KeyState (VAR keys: SET);

(* Restricts the extent of the mouse coordinates returned by Mouse. *)
 PROCEDURE SetMouseLimits (x, y, w, h: INTEGER); (* non-portable *)

(* Configure input device parameters.  Normally only used by installation program.
*)
 PROCEDURE Configure (config, value: ARRAY OF CHAR); (* non-portable *)

(* Add a mouse driver.  The poll procedure will be called from Mouse and should
return the next mouse event, including the current key state.  It returns TRUE
iff a mouse event is available. *)
 PROCEDURE AddMouse (poll: PollMouse); (* non-portable *)

(* Remove a mouse driver. *)
 PROCEDURE RemoveMouse (poll: PollMouse); (* non-portable *)

(* Add a keyboard driver.  The poll procedure will be called from Available
and Read and should return the next ASCII character.  It returns TRUE iff a
key is available.  The current shift state (SHIFT, CTRL, ALT) should always
be returned, and will be added to KeyState. *)
 PROCEDURE AddKeyboard (poll: PollKeyboard); (* non-portable *)

(* Remove a keyboard driver. *)
 PROCEDURE RemoveKeyboard (poll: PollKeyboard); (* non-portable *)
END Input.

(* Remarks:

1. Keyboard character codes correspond to the ASCII character set. 
Some other important codes are:

 F1, SETUP 0A4X
 F2, NEUTRALISE 0A5X
 F3, SCRL 0A6X (used in Draw)
 F4, NOSCRL 0A7X (used in Draw)
 UP ARROW 0C1X
 RIGHT ARROW 0C3X
 DOWN ARROW 0C2X
 LEFT ARROW 0C4X
 INSERT 0A0X
 DELETE 0A1X
 PAGE-UP 0A2X
 PAGE-DOWN 0A3X
 ä, Ä 131, 128
 ö, Ö 132, 129
 ü, Ü 133, 130
  150

The module EditKeys allows you to determine the keyboard code of any key pressed.

For cross-platform portability, Oberon does not normally support all keys available

on your keyboard.
*)