Unit uInput

The code of unit uInput

unit uInput;
{
    Copyright (c) 2011 Christopher Winward

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}
{$mode objfpc}

interface

uses
  Classes, SysUtils, sdl;

var
  mouseX, mouseY : integer;
  mouse1Down, mouse2Down, deleteButton, insertButton : boolean;

procedure updateInputs;

implementation

procedure updateInputs;
var
  event : TSDL_Event;
begin
  while (SDL_PollEvent(@event) > 0) do //Poll every event until there are none left.
    begin
      case (event.type_) of
        SDL_KEYDOWN : case (event.key.keysym.sym) of
                        SDLK_ESCAPE : halt;
                        SDLK_Delete : deleteButton := true;
                        SDLK_Insert : insertButton := true;
                      end;

        SDL_KEYUP : case (event.key.keysym.sym) of
                      SDLK_Delete : deleteButton := false;
                      SDLK_Insert : insertButton := false;
                    end;

        SDL_MOUSEBUTTONDOWN : case (event.button.button) of
                                1 : mouse1Down := true;
                                3 : mouse2Down := true;
                              end;

        SDL_MOUSEBUTTONUP : case (event.button.button) of
                              1 : mouse1Down := false;
                              3 : mouse2Down := false;
                            end;
      end;
    end;

  SDL_GetMouseState(mouseX, mouseY);

  //Look at http://freepascal-meets-sdl.net/ Chapter 6, Event handling for more information.
end;

end.
Programming - a skill for life!

by Christopher Winward: U6 Age 17