mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-18 05:00:07 +02:00
+ Removed need for keybutil unit by incorporating it in the keyboard unit
This commit is contained in:
parent
148dbc6022
commit
96d51ec257
@ -46,7 +46,7 @@ onetex : tex
|
||||
$(MAKETEX) $(TEXOBJECTS)
|
||||
|
||||
clean :
|
||||
rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS) keybutil.ppu
|
||||
rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS)
|
||||
|
||||
$(OBJECTS): %: %.pp
|
||||
$(PP) $(PPOPTS) $*
|
||||
|
@ -1,7 +1,5 @@
|
||||
This directory contains the examples for the Keyboard unit
|
||||
|
||||
keybutil.pp contains some routines to convert keyevents to readable strings.
|
||||
|
||||
ex1.pp contains an example of the GetKeyEvent function.
|
||||
ex2.pp contains an example of the GetKeyEventCode function.
|
||||
ex3.pp contains an example of the GetKeyEventShiftState function.
|
||||
|
@ -2,7 +2,7 @@ program example1;
|
||||
|
||||
{ This program demonstrates the GetKeyEvent function }
|
||||
|
||||
uses keyboard, keybutil;
|
||||
uses keyboard;
|
||||
|
||||
Var
|
||||
K : TKeyEvent;
|
||||
|
@ -2,7 +2,7 @@ Program Example2;
|
||||
|
||||
{ Program to demonstrate the GetKeyEventCode function. }
|
||||
|
||||
Uses keyboard,KeybUtil;
|
||||
Uses keyboard;
|
||||
|
||||
Var
|
||||
K : TKeyEvent;
|
||||
|
@ -2,7 +2,7 @@ Program Example3;
|
||||
|
||||
{ Program to demonstrate the GetKeyEventShiftState function. }
|
||||
|
||||
Uses keyboard,KeybUtil;
|
||||
Uses keyboard;
|
||||
|
||||
Var
|
||||
K : TKeyEvent;
|
||||
|
@ -2,7 +2,7 @@ program example4;
|
||||
|
||||
{ This program demonstrates the PollKeyEvent function }
|
||||
|
||||
uses keyboard, keybutil;
|
||||
uses keyboard;
|
||||
|
||||
Var
|
||||
K : TKeyEvent;
|
||||
|
@ -2,7 +2,7 @@ program example5;
|
||||
|
||||
{ This program demonstrates the PutKeyEvent function }
|
||||
|
||||
uses keyboard, keybutil;
|
||||
uses keyboard;
|
||||
|
||||
Var
|
||||
K,k2 : TKeyEvent;
|
||||
|
@ -2,7 +2,7 @@ program example6;
|
||||
|
||||
{ This program demonstrates the PollShiftStateEvent function }
|
||||
|
||||
uses keyboard, keybutil;
|
||||
uses keyboard;
|
||||
|
||||
Var
|
||||
K : TKeyEvent;
|
||||
|
@ -2,7 +2,7 @@ program example1;
|
||||
|
||||
{ This program demonstrates the GetKeyEvent function }
|
||||
|
||||
uses keyboard, keybutil;
|
||||
uses keyboard;
|
||||
|
||||
Var
|
||||
K : TKeyEvent;
|
||||
|
@ -1,106 +0,0 @@
|
||||
unit keybutil;
|
||||
|
||||
Interface
|
||||
|
||||
Uses keyboard;
|
||||
|
||||
Type
|
||||
TKeyRecord = packed record
|
||||
KeyCode : Word;
|
||||
ShiftState, Flags : Byte;
|
||||
end;
|
||||
|
||||
Const
|
||||
// Only use these strings. Should be used to localize key names.
|
||||
SShift : Array [1..3] of string[5] = ('SHIFT','CTRL','ALT');
|
||||
SLeftRight : Array [1..2] of string[5] = ('LEFT','RIGHT');
|
||||
SUnicodeChar : String = 'Unicode character ';
|
||||
SScanCode : String = 'Key with scancode ';
|
||||
SUnknownFunctionKey : String = 'Unknown function key : ';
|
||||
SAnd : String = 'AND';
|
||||
SKeyPad : Array [0..($FF2F-kbdHome)] of string[6] =
|
||||
('Home','Up','PgUp','Left',
|
||||
'Middle','Right','End','Down',
|
||||
'PgDn','Insert','Delete','',
|
||||
'','','','');
|
||||
|
||||
Function ShiftStateToString(KeyEvent : TKeyEvent; UseLeftRight : Boolean) : String;
|
||||
Function FunctionKeyName (KeyCode : Word) : String;
|
||||
Function KeyEventToString(KeyEvent : TKeyEvent) : String;
|
||||
|
||||
|
||||
Implementation
|
||||
|
||||
Procedure AddToString (Var S : String; Const A : String);
|
||||
|
||||
begin
|
||||
If Length(S)=0 then
|
||||
S:=A
|
||||
else
|
||||
S:=S+' '+A;
|
||||
end;
|
||||
|
||||
Function IntToStr(Int : Longint) : String;
|
||||
|
||||
begin
|
||||
Str(Int,IntToStr);
|
||||
end;
|
||||
|
||||
Function ShiftStateToString(KeyEvent : TKeyEvent; UseLeftRight : Boolean) : String;
|
||||
|
||||
Var
|
||||
S : Integer;
|
||||
T : String;
|
||||
|
||||
begin
|
||||
S:=GetKeyEventShiftState(KeyEvent);
|
||||
T:='';
|
||||
If (S and kbShift)<>0 then
|
||||
begin
|
||||
if UseLeftRight then
|
||||
case (S and kbShift) of
|
||||
kbShift : AddToString(T,SLeftRight[1]+' '+SAnd+' '+SLeftRight[2]);
|
||||
kbLeftShift : AddToString(T,SLeftRight[1]);
|
||||
kbRightShift : AddToString(T,SLeftRight[2]);
|
||||
end;
|
||||
AddToString(T,SShift[1]);
|
||||
end;
|
||||
If (S and kbCtrl)<>0 Then
|
||||
AddToString(T,SShift[2]);
|
||||
If (S and kbAlt)<>0 Then
|
||||
AddToString(T,SShift[3]);
|
||||
ShiftStateToString:=T;
|
||||
end;
|
||||
|
||||
Function FunctionKeyName (KeyCode : Word) : String;
|
||||
|
||||
begin
|
||||
If ((KeyCode-KbdF1)<$1F) Then
|
||||
FunctionKeyName:='F'+IntToStr((KeyCode-KbdF1+1))
|
||||
else
|
||||
begin
|
||||
If (KeyCode-kbdHome)<($2F-$1F) then
|
||||
FunctionKeyName:=SKeyPad[(KeyCode-kbdHome)]
|
||||
else
|
||||
FunctionKeyName:=SUnknownFunctionKey + IntToStr(KeyCode);
|
||||
end;
|
||||
end;
|
||||
|
||||
Function KeyEventToString(KeyEvent : TKeyEvent) : String;
|
||||
|
||||
Var
|
||||
T : String;
|
||||
|
||||
begin
|
||||
T:=ShiftStateToString(KeyEvent,False);
|
||||
Case GetKeyEventFlags(KeyEvent) of
|
||||
kbASCII : AddToString(T,GetKeyEventChar(KeyEvent));
|
||||
kbUniCode : AddToString(T,SUniCodeChar+IntToStr(GetKeyEventUniCode(Keyevent)));
|
||||
kbFnKey : AddToString(T,FunctionKeyName(GetKeyEventCode(KeyEvent)));
|
||||
// Not good, we need a GetKeyEventScanCode function !!
|
||||
kbPhys : AddToString(T,SScanCode+IntToStr(KeyEvent and $ffff));
|
||||
end;
|
||||
KeyEventToString:=T;
|
||||
end;
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user