%
% Keyboard controls for typical PC keyboard with numeric keypad.  Controls
% for a single-engine aircraft with two main wheel brakes DB_0 (left) and DB_1
% (right).  Attention:  Key names are uppercase only!
%
% Key names are as defined in Qt, but without the Key_ prefix.  See
%   http://doc.trolltech.com/3.3/qt.html#Key-enum
%
% Keys can be defined with modifiers:  Shift, Control, Alt, Meta.
%
% Variable names are:
%   DF, DG:  Flaps, gear (0 = retracted, 1 = extended)
%   DA, DE, DR:  Aileron, elevator, rudder (-1..1).
%   DE_T:  Elevator trim (-1..1).
%   DP_i:  i-th power lever (counting from 0; (0..1)).
%   DB_i:  i-th wheel brake (counting from 0 (left brake); (0..1))
%
% Manipulators are:
%   set(var, value):  Set var to value.
%   add(var, delta [, min, max]):  Add delta to var, keep it between min
%                                  and max if given.
%   toggle(var):  Set var to 0 if it's 1 or to 1 otherwise.
%   toggle(var, min, max, step) Change var between min and max adding step.
%

%
% This keymapping works well on standard US keyboards with NumLock switched off
% and on reduced keyboards without the numeric keypad by providing some
% alternate mappings.  Also works with most European type keyboards, as the
% only punctuation characters used are the period and comma (for brakes).
%
% The key_press list defines actions to be executed on key presses with
% an optional modifier key.  For set() statements with nonzero value, the
% corresponding variable is set to zero when the key is released.
%

key_press = [
  % Numeric keypad without NumLock.
  Prior            set(dDP_0, +0.8)
  Next             set(dDP_0, -0.8)
  '9'              set(dDP_0, +0.8)
  '3'              set(dDP_0, -0.8)
  Left             set(dDA, -0.8)
  Right            set(dDA, +0.8)
  '4'              set(dDA, -0.8)
  '6'              set(dDA, +0.8)
  Up               set(dDE, -0.8)
  Down             set(dDE, +0.8)
  '8'              set(dDE, -0.8)
  '2'              set(dDE, +0.8)
  Insert           set(dDR, -0.8)
  '0'              set(dDR, -0.8)
  Enter            set(dDR, +0.8)
  Shift Left       set(dDR, -0.8)
  Shift Right      set(dDR, +0.8)
  Home             set(dDE_T, -0.8)
  End              set(dDE_T, +0.8)
  Shift Up         set(dDE_T, -0.8)
  Shift Down       set(dDE_T, +0.8)

  % 'Clear' is the 5 in the center of the keypad.
  Clear            set(DA, 0)
  Clear            set(DR, 0)
  Clear            set(dDA, 0)
  Clear            set(dDR, 0)
  '5'              set(DA, 0)
  '5'              set(DR, 0)
  '5'              set(dDA, 0)
  '5'              set(dDR, 0)


  % Keys on the normal keyboard.
  BracketLeft      add(DF, -.2, 0, 1)
  BracketRight     add(DF,  .2, 0, 1)
  Shift F          add(DF, -.2, 0, 1)
  F                add(DF,  .2, 0, 1)
  Comma            set(DB_0, 1)
  Period           set(DB_1, 1)
  G                toggle(DG)
  C                set(DA, 0)
  C                set(DR, 0)

  % Freeze/Pause
  Space            toggle(TotalFreeze)
  H                toggle(HUDEnabled)
  H                toggle(ControlsIndicationEnabled)
  % Fast movement
  % 10 degrees
  Ctrl Up          add(VAngle, +0.174533)
  Ctrl Down        add(VAngle, -0.174533)
  % 45 degrees
  Ctrl Left        add(HAngle, -0.785398)
  Ctrl Right       add(HAngle, +0.785398)
  % Slow movement
  Alt Up           set(dVAngle, +0.1)
  Alt Down         set(dVAngle, -0.1)
  Alt Left         set(dHAngle, -0.1)
  Alt Right        set(dHAngle, +0.1)
  V                set(HAngle, 0)
  V                set(VAngle, 0)
  V                set(dHAngle, 0)
  V                set(dVAngle, 0)
]
