Browse Source

+ initial implementation

michael 24 years ago
parent
commit
ac4225a280
6 changed files with 176 additions and 0 deletions
  1. 54 0
      docs/kbdex/Makefile
  2. 2 0
      docs/kbdex/foot.tex
  3. 3 0
      docs/kbdex/head.tex
  4. 101 0
      docs/kbdex/keybutil.pp
  5. 8 0
      docs/kbdex/newex
  6. 8 0
      docs/kbdex/template.pp

+ 54 - 0
docs/kbdex/Makefile

@@ -0,0 +1,54 @@
+#######################################################################
+#
+# Makefile to compile all examples and convert them to LaTeX
+# 
+#######################################################################
+
+# Compiler
+PP=ppc386
+
+# Unit directory
+# UNITDIR=/usr/lib/ppc/0.99.0/linuxunits
+
+
+# Any options you wish to pass.
+PPOPTS=
+
+# Script to convert the programs to LaTeX examples which can be included.
+PP2TEX=../pp2tex
+
+# Script to collect all examples in 1 file.
+MAKETEX=make1tex
+
+#######################################################################
+# No need to edit after this line.
+#######################################################################
+
+ifdef UNITDIR
+PPOPTS:=$(PPOPTS) -Up$(UNITDIR);
+endif
+
+.SUFFIXES: .pp .tex
+
+.PHONY: all tex clean
+
+OBJECTS=rttiobj trtti1 trtti2 trtti3 ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 \
+        ex10 ex11 ex12 ex13  ex14 ex15 ex16 ex17 ex18
+
+TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
+
+all : $(OBJECTS)
+
+tex : $(TEXOBJECTS)
+
+onetex : tex
+	$(MAKETEX) $(TEXOBJECTS)
+
+clean : 
+	rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS) rttiobj.ppu
+ 
+$(OBJECTS): %: %.pp
+	$(PP) $(PPOPTS) $*
+
+$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
+	$(PP2TEX) $*

+ 2 - 0
docs/kbdex/foot.tex

@@ -0,0 +1,2 @@
+\end{verbatim}
+\end{FPCList}

+ 3 - 0
docs/kbdex/head.tex

@@ -0,0 +1,3 @@
+\begin{FPCList}
+\item[Example]
+\begin{verbatim}

+ 101 - 0
docs/kbdex/keybutil.pp

@@ -0,0 +1,101 @@
+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 = ('SHIFT','CTRL','ALT');
+  SLeftRight   : Array [1..2] of string = ('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 = 
+                 ('Home','Up','PgUp','Left',
+                  'Middle','Right','End','Down',
+                  'PgDn','Insert','Delete','',
+                  '','','','');
+
+
+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 ShiftStateString(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[2]);
+  ShiftStateString:=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:=ShiftStateString(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;   
+end;
+  
+end. 

+ 8 - 0
docs/kbdex/newex

@@ -0,0 +1,8 @@
+#!/bin/sh
+if [ -e ex${1}.pp ]; then
+  mv ex${1}.pp ex${1}.pp.orig
+fi
+sed -e s/Example/Example$1/ -e s/\\\*\\\*\\\*/$2/ <template.pp >ex${1}.pp
+echo "ex${1}.pp contains an example of the $2 function." >>README
+joe ex${1}.pp
+ppc386 ex${1}.pp && ex${1}

+ 8 - 0
docs/kbdex/template.pp

@@ -0,0 +1,8 @@
+Program Example;
+
+{ Program to demonstrate the *** function. }
+
+Uses keyboard;
+
+begin
+end.