REM OPL code for single-line text input on Series 60 with mulit-tap of numerical keys REM REM Created by Martin Dehler 12/2004 - martin.dehler@gmx.de - www.martin-dehler.de REM Version 0.10 - www.martin-dehler.de/opl/multitap.htm REM REM Feel free to use and modify the code as you need. REM Please don't expect the code to be bug free, but as a basis to work on ;-) REM REM The code demonstrates a very basic way of entering an up to 255 charcters long string REM in a single line. Characters are entered by single or multiple taps on the numerical REM keypad. The #-key switches between lower- and uppercase charcters. The C-key deletes REM the last character. The cursor can be moved along the text with the right and left key. REM REM Major backdraws are the lack of more sophisticated upper- and lowercase handling (e.g. REM automatic switch to uppercase after a period) and that the speed decreases with longer REM strings. REM modify to point to point to S60 constants file INCLUDE "const_series60.oph" CONST KKeySoftLeft32&=63554 CONST KKeySoftRight32&=63555 CONST KKeyNaviLeft32&=63495 CONST KKeyNaviRight32&=63496 CONST KKeyClear32&=8 REM constants for text input CONST KMaxChar%=255 REM up to 255 CONST KMargin%=5 REM in pixels, used for left and right margin CONST KCapitalLow%=1 REM don't modify CONST KCapitalAll%=2 REM don't modify PROC TextInput: GLOBAL Event&(16),MenuKey%,Key&,PrevKey&,KeyCount% GLOBAL TimeStamp&,TimeStamp$(255),TimeAct&,TimePrev&,TimeDiff& GLOBAL Char$(20,30),Text$(255),Temp$(255),TextWidth%,Capital%,Line$(60) GLOBAL CursorPos%,PrevCursorPos% REM lowercase characters Char$(1)=".,?!1@'-_():;&/%*#+<=>"+CHR$(34)+"$"+CHR$(163)+"§"+CHR$(165) Char$(2)="abc2ä" Char$(3)="def3" Char$(4)="ghi4" Char$(5)="jkl5"+CHR$(163) Char$(6)="mno6ö" Char$(7)="pqrs7ß$" Char$(8)="tuv8ü" Char$(9)="wxyz9" Char$(10)=" 0" REM capitalized characters Char$(11)=".,?!1@'-_():;&/%*#+<=>"+CHR$(34)+"$"+CHR$(163)+"§"+CHR$(165) Char$(12)="ABC2Ä" Char$(13)="DEF3" Char$(14)="GHI4" Char$(15)="JKL5"+CHR$(163) Char$(16)="MNO6Ö" Char$(17)="PQRS7$" Char$(18)="TUV8Ü" Char$(19)="WXYZ9" Char$(20)=" 0" REM initialisation Capital%=KCapitalLow% TextWidth%=gWIDTH-(2*KMargin%) DrawMainBackground: DrawMainVariabel: REM main loop DO GETEVENT32 Event&() IF (Event&(1) AND &400)=0 REM key event Key&=Event&(1) REM processing key presses IF Key&=KKeySoftLeft32& REM menu mINIT mCARD "","Exit",%e MenuKey%=MENU ELSEIF Key&=KKeySoftRight32& Shutdown: ELSEIF Key&=48 OR Key&=49 OR Key&=50 OR Key&=51 OR Key&=52 OR Key&=53 OR Key&=54 OR Key&=55 OR Key&=56 OR Key&=57 REM numerical keys - text input REM determine actual time TimeStamp&=Event&(2) TimeStamp$=GEN$(TimeStamp&,255) REM delete leading '-' IF LEFT$(TimeStamp$,1)="-" TimeStamp$=MID$(TimeStamp$,2,LEN(TimeStamp$)-1) ENDIF REM truncate time stamp TimeStamp$=MID$(TimeStamp$,1,LEN(TimeStamp$)-4) TimeAct&=VAL(TimeStamp$) REM calculate time since previous key press TimeDiff&=IABS(TimeAct&-TimePrev&) REM if time to long, reset to first character in charcter string IF TimeDiff&>100 OR PrevKey&<>Key& KeyCount%=0 ENDIF TimePrev&=TimeAct& IF LEN(Text$)0 REM C key, backspace IF CursorPos%=LEN(Text$) Text$=LEFT$(Text$,LEN(Text$)-1) PrevCursorPos%=CursorPos% CursorPos%=LEN(Text$) ELSEIF CursorPos%>0 Text$=LEFT$(Text$,CursorPos%-1)+RIGHT$(Text$,LEN(Text$)-CursorPos%) PrevCursorPos%=CursorPos% CursorPos%=CursorPos%-1 ENDIF DrawMainVariabel: ELSEIF Key&=35 REM #-key, switches between lower and uppercase characters IF Capital%=KCapitalLow% Capital%=KCapitalAll% ELSEIF Capital%=KCapitalAll% Capital%=KCapitalLow% ENDIF DrawMainVariabel: ELSEIF Key&=KKeyNaviLeft32& REM scroll cursor left IF CursorPos%>0 PrevCursorPos%=CursorPos% CursorPos%=CursorPos%-1 ELSEIF CursorPos%=0 CursorPos%=LEN(Text$) ENDIF DrawMainVariabel: ELSEIF Key&=KKeyNaviRight32& REM scroll cursor right IF CursorPos%0 Text$=LEFT$(Text$,CursorPos%-1)+RIGHT$(Text$,LEN(Text$)-CursorPos%) CursorPos%=CursorPos%-1 ENDIF ENDIF REM append selected character Text$=LEFT$(Text$,CursorPos%)+MID$(Char$(Char%),KeyCount%,1)+RIGHT$(Text$,LEN(Text$)-CursorPos%) PrevCursorPos%=CursorPos% CursorPos%=CursorPos%+1 REM reset to begin of charcater string when last charcater is reached in string IF KeyCount%=LEN(Char$(Char%)) KeyCount%=0 ENDIF ENDP PROC DrawMainBackground: REM draw softkey labels gUSE 1 gFONT KFontS60LatinBold17& gAT 2,204 :gPRINT "Menu" gAT 176-gTWIDTH("Exit"),204 :gPRINT "Exit" ENDP PROC DrawMainVariabel: REM draws the string and other variabel screen content LOCAL X%,Temp$(255),Space%,TempLine$(255),CharCount$(3),MaxChar$(3),DrawCursor% gUSE 1 gFONT KFontS60LatinBold12& CURSOR OFF REM draw character size indicator gAT KMargin%,15 IF Capital%=KCapitalLow% gPRINTB "abc",30 ELSEIF Capital%=KCapitalAll% gPRINTB "ABC",30 ENDIF REM draw character count CharCount$=GEN$(LEN(Text$),3) MaxChar$=GEN$(KMaxChar%,3) gAT gWIDTH-(gTWIDTH("000("+MaxChar$+")")+KMargin%),15 REM the triple 0 is a 'placeholder' for max 3 digit numbers gPRINTB CharCount$+"("+MaxChar$+")",gTWIDTH("000("+MaxChar$+")"),1 REM clear text Line$="" REM calculate text to show IF gTWIDTH(Text$)<=TextWidth% Line$=Text$ DrawCursor%=CursorPos% ELSE REM text wider than text width IF gTWIDTH(LEFT$(Text$,CursorPos%))=TextWidth% Line$=LEFT$(TempLine$,X%-2) DrawCursor%=CursorPos% ELSEIF gTWIDTH(RIGHT$(Text$,LEN(Text$)-CursorPos%))=TextWidth%/2 REM text left of cursor X%=1 DO Temp$=MID$(Text$,(CursorPos%+1)-X%,X%) X%=X%+1 UNTIL gTWIDTH(Temp$+TempLine$)>=TextWidth% Line$=Temp$+TempLine$ DrawCursor%=X%-1 REM cut off rightmost character to fit in text width IF gTWIDTH(Line$)>TextWidth% X%=1 DO Line$=LEFT$(Line$,LEN(Line$)-X%) X%=X%+1 UNTIL gTWIDTH(Line$)<=TextWidth% ENDIF ENDIF ENDIF REM draw text gAT KMargin%,35 gPRINTB Line$,TextWidth% REM draw cursor gAT KMargin%+gTWIDTH(LEFT$(Line$,DrawCursor%)),35 CURSOR 1,10,1,13 ENDP PROC Shutdown: STOP ENDP