Want to see what people are talking about? See the latest forum posts.
*/
*/

View YS\YSKB.pas

Yeakisen's Snake v1.0

Submitted By: Yeakisen
Rating: Not rated (Rate It)


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                            !Yeakisen's Snake!                              //
//                       Yeakisen Productions (2007)                          //
//                              Keyboard Unit                                 //
//                     Written by Matthew Gianfrancesco                       //
//                            December 12, 2007                               //
//                       Completed December 23, 2007                          //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
UNIT YSKB;

INTERFACE

CONST
    KeyLeftArrow=37;
    KeyRightArrow=39;
    KeyUpArrow=38;
    KeyDownArrow=40;
    KeyEnter=13;

PROCEDURE InitYSKB;
PROCEDURE ClearInput;
FUNCTION Key_Down:Boolean;
FUNCTION Get_Key:Byte;

IMPLEMENTATION

USES
    Windows;

VAR
    InputHandle:THandle;

PROCEDURE InitYSKB;
    BEGIN
    InputHandle:=GetStdHandle(STD_INPUT_HANDLE);
    END;

PROCEDURE ClearInput;
    BEGIN
    FlushConsoleInputBuffer(InputHandle);
    END;

FUNCTION Key_Down:Boolean;
    VAR
    InputData:TInputRecord;
    EventsRead:Cardinal;
    NumberOfEvents:Cardinal;
    Quitter:Boolean;
    BEGIN
    Quitter:=FALSE;
    REPEAT
        GetNumberOfConsoleInputEvents(InputHandle,NumberOfEvents);
        IF(NumberOfEvents>0)THEN
            BEGIN
            PeekConsoleInput(InputHandle,InputData,1,EventsRead);
            IF(InputData.EventType=1)AND(InputData.Event.KeyEvent.bKeyDown=TRUE)THEN
                BEGIN
                Result:=TRUE;
                Quitter:=TRUE;
                END
            ELSE
                BEGIN
                Result:=FALSE;
                ReadConsoleInput(InputHandle,InputData,1,EventsRead);
                END;
            END
        ELSE
            Quitter:=TRUE;
    UNTIL(Quitter=TRUE);
    END;

FUNCTION Get_Key:Byte;
    VAR
    InputData:TInputRecord;
    EventsRead:Cardinal;
    NumberOfEvents:Cardinal;
    Counter:Cardinal;
    BEGIN
    GetNumberOfConsoleInputEvents(InputHandle,NumberOfEvents);
    IF(NumberOfEvents>0)THEN
        BEGIN
        FOR Counter:=1 TO NumberOfEvents DO
            BEGIN
            ReadConsoleInput(InputHandle,InputData,1,EventsRead);
            END;
        Result:=InputData.Event.KeyEvent.wVirtualKeyCode;
        END;
    END;

END.

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings