123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- {
- $Id$
- This file is part of the Free Pascal run time library.
- Copyright (c) 1999-2000 by Florian Klaempfl
- member of the Free Pascal development team
- This is unit implements some of the crt functionality
- for the gui win32 graph unit implementation
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- unit wincrt;
- interface
- function readkey : char;
- function keypressed : boolean;
- procedure delay(ms : word);
- { dummy }
- procedure textmode(mode : integer);
- { plays the windows standard sound }
- { hz is ignored (at least on win95 }
- procedure sound(hz : word);
- { dummy }
- procedure nosound;
- var
- directvideo : boolean;
- { dummy }
- lastmode : word;
- implementation
- uses
- windows,graph;
- const
- keybuffersize = 32;
- var
- keyboardhandling : TCriticalSection;
- keybuffer : array[1..keybuffersize] of char;
- nextfree,nexttoread : longint;
- procedure inccyclic(var i : longint);
- begin
- inc(i);
- if i>keybuffersize then
- i:=1;
- end;
- procedure addchar(c : char);
- begin
- EnterCriticalSection(keyboardhandling);
- keybuffer[nextfree]:=c;
- inccyclic(nextfree);
- { skip old chars }
- if nexttoread=nextfree then
- begin
- // special keys are started by #0
- // so we've to remove two chars
- if keybuffer[nexttoread]=#0 then
- inccyclic(nexttoread);
- inccyclic(nexttoread);
- end;
- LeaveCriticalSection(keyboardhandling);
- end;
- function readkey : char;
- begin
- while true do
- begin
- EnterCriticalSection(keyboardhandling);
- if nexttoread<>nextfree then
- begin
- readkey:=keybuffer[nexttoread];
- inccyclic(nexttoread);
- LeaveCriticalSection(keyboardhandling);
- exit;
- end;
- LeaveCriticalSection(keyboardhandling);
- { give other threads a chance }
- Windows.Sleep(10);
- end;
- end;
- function keypressed : boolean;
- begin
- EnterCriticalSection(keyboardhandling);
- keypressed:=nexttoread<>nextfree;
- LeaveCriticalSection(keyboardhandling);
- end;
- procedure delay(ms : word);
- begin
- Sleep(ms);
- end;
- procedure textmode(mode : integer);
- begin
- end;
- procedure sound(hz : word);
- begin
- Windows.Beep(hz,500);
- end;
- procedure nosound;
- begin
- end;
- procedure addextchar(c : char);
- begin
- addchar(#0);
- addchar(c);
- end;
- const
- altkey : boolean = false;
- ctrlkey : boolean = false;
- shiftkey : boolean = false;
- function msghandler(Window: HWnd; AMessage:UInt; WParam : WParam; LParam: LParam): Longint; stdcall;
- begin
- case amessage of
- WM_CHAR:
- begin
- addchar(chr(wparam));
- end;
- WM_KEYDOWN:
- begin
- case wparam of
- VK_LEFT:
- addextchar(#75);
- VK_RIGHT:
- addextchar(#77);
- VK_DOWN:
- addextchar(#80);
- VK_UP:
- addextchar(#72);
- VK_INSERT:
- addextchar(#82);
- VK_DELETE:
- addextchar(#83);
- VK_END:
- addextchar(#79);
- VK_HOME:
- addextchar(#71);
- VK_PRIOR:
- addextchar(#73);
- VK_NEXT:
- addextchar(#81);
- VK_F1..VK_F10:
- begin
- if ctrlkey then
- addextchar(chr(wparam+24))
- else if altkey then
- addextchar(chr(wparam+34))
- else
- addextchar(chr(wparam-11));
- end;
- VK_CONTROL:
- ctrlkey:=true;
- VK_MENU:
- altkey:=true;
- VK_SHIFT:
- shiftkey:=true;
- end;
- end;
- WM_KEYUP:
- begin
- case wparam of
- VK_CONTROL:
- ctrlkey:=false;
- VK_MENU:
- altkey:=false;
- VK_SHIFT:
- shiftkey:=false;
- end;
- end;
- end;
- msghandler:=0;
- end;
- var
- oldexitproc : pointer;
- procedure myexitproc;
- begin
- exitproc:=oldexitproc;
- charmessagehandler:=nil;
- DeleteCriticalSection(keyboardhandling);
- end;
- begin
- charmessagehandler:=@msghandler;
- nextfree:=1;
- nexttoread:=1;
- InitializeCriticalSection(keyboardhandling);
- oldexitproc:=exitproc;
- exitproc:=@myexitproc;
- lastmode:=0;
- end.
- {
- $Log$
- Revision 1.5 2003-04-23 11:35:00 peter
- * wndproc definition fixed
- Revision 1.4 2003/04/23 11:22:12 peter
- * fixed msghandler declarations
- Revision 1.3 2002/09/07 16:01:29 peter
- * old logs removed and tabs fixed
- }
|