REM Project: Writing Recognition REM Created: 9/28/2006 4:28:19 PM REM REM ***** Main Source File ***** REM remstart uppercase=up backspace=left,up space=right,up a=up-right,down-right b=down,up,right,down,left c=left,down,right d=left,down,right,up e=right,up,left,down,right f=up,left,down g=left,down,right,up,down,left h=down,up,right,down i=down j=down,left,up k=down,up,right,down,left,down-right or down-left,down-right l=down,right m=down,up,right,down,up,right,down n=up,right,down o=left,down,right,up,left p=up,left,down,right q=left,down,right,up,down r=down,up,right s=left,down,right,down,left t=down,up,left u=down,right,up v=down-right,up-right w=down,right,up,down,right,up x=down-right y=down,left,up,down,left z=right,down-left,right remend disable escapekey sync on cls load dll "User32.dll",1 `Declaring all varibales, dirrection keeps the directions of the mouse `x and y are for the drawn lines dim dirrection(100) dim command(20) dim x(100000) dim y(100000) lin=1 nextdir=1 width=screen width() fort=width/40 `main loop do sync CLS rgb(255,255,255) for i=1 to 26 pressed=button(chr$(64+i),screen width()-50,(i-1)*20) if pressed=1 button$=chr$(96+i) gosub buttonpressed call dll 1,"MessageBoxA",0,"Character "+chr$(64+i)+"="+instructions$,"The letter "+chr$(64+i),0 gosub buttonpressed2 gosub drawit endif next i if escapekey()=1 call dll 1,"MessageBoxA",0,"Thanks for using Spopovich's handwriting recognition program","Quit",0 print responce write to clipboard sentence$ end endif line 0,screen height()/2,screen width()-100,screen height()/2 line 0,screen height()/2-100,screen width()-100,screen height()/2-100 ink rgb(0,0,200),rgb(0,0,200) for i=0 to 36 line fort*i,screen height()/2-50,fort*i+10,screen height()/2-50 next i ink 0,0 text 0,0,letter$ text 0,screen height()-text height(sentence$),sentence$ x=mousemovex() y=mousemovey() x(lin)=mousex() y(lin)=mousey() lin=lin+1 `draws where the mouse moves if mouseclick()=3 for i=2 to lin-1 line x(i),y(i),x(i-1),y(i-1) next i endif `when the mouse button is let go checks for what letter was drawn if mouseclick()=0 gosub recognize lin=1 undim x(100000) undim y(100000) dim x(100000) dim y(100000) endif olddirection=direction `if there is a change in the direction then it records it if olddirection=direction and direction<>0 and direction<>dirrection(nextdir-1) and mouseclick()=3 dirrection(nextdir)=direction nextdir=nextdir+1 endif `detirmines the direction the mouse is moving `1=right, -1=left,2=down,-2=up `3=down-right,-3=down-left,4=up-right,-4=up-left if x>0 and y>=-1 and y=<1 and direction<>3 and direction<>4 then direction=1 if x<0 and y>=-1 and y=<1 and direction<>-3 and direction<>-4 then direction=-1 if y>0 and x>=-1 and x=<1 and direction<>3 and direction<>-3 then direction=2 if y<0 and x>=-1 and x=<1 and direction<>4 and direction<>-4 then direction=-2 if x>1 and y>1 and direction<>1 and direction<>2 then direction=3 if x<-1 and y>1 and direction<>-1 and direction<>2 then direction=-3 if x>1 and y<-1 and direction<>1 and direction<>-2 then direction=4 if x<-1 and y<-1 and direction<>-1 and direction<>-2 then direction=-4 wait 20 loop `The subroutine to detect what letter is being made recognize: if nextdir>=7 if dirrection(nextdir-1)=2 and dirrection(nextdir-2)=1 and dirrection(nextdir-3)=-2 and dirrection(nextdir-4)=2 and dirrection(nextdir-5)=1 and dirrection(nextdir-6)=-2 and dirrection(nextdir-7)=2 letter$="m" nextdir=1 goto donecheck endif endif if nextdir>=6 if dirrection(nextdir-1)=-1 and dirrection(nextdir-2)=2 and dirrection(nextdir-3)=-2 and dirrection(nextdir-4)=1 and dirrection(nextdir-5)=2 and dirrection(nextdir-6)=-1 letter$="g" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=3 and dirrection(nextdir-2)=-1 and dirrection(nextdir-3)=2 and dirrection(nextdir-4)=1 and dirrection(nextdir-5)=-2 and dirrection(nextdir-6)=2 letter$="k" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-2 and dirrection(nextdir-2)=1 and dirrection(nextdir-3)=2 and dirrection(nextdir-4)=-2 and dirrection(nextdir-5)=1 and dirrection(nextdir-6)=2 letter$="w" nextdir=1 goto donecheck endif endif if nextdir>=5 if dirrection(nextdir-1)=-1 and dirrection(nextdir-2)=2 and dirrection(nextdir-3)=1 and dirrection(nextdir-4)=-2 and dirrection(nextdir-5)=2 letter$="b" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-1 and dirrection(nextdir-2)=2 and dirrection(nextdir-3)=-2 and dirrection(nextdir-4)=1 and dirrection(nextdir-5)=2 letter$="y" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=1 and dirrection(nextdir-2)=2 and dirrection(nextdir-3)=-1 and dirrection(nextdir-4)=-2 and dirrection(nextdir-5)=1 letter$="e" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=2 and dirrection(nextdir-2)=-2 and dirrection(nextdir-3)=1 and dirrection(nextdir-4)=2 and dirrection(nextdir-5)=-1 letter$="q" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-1 and dirrection(nextdir-2)=2 and dirrection(nextdir-3)=1 and dirrection(nextdir-4)=2 and dirrection(nextdir-5)=-1 letter$="s" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-1 and dirrection(nextdir-2)=-2 and dirrection(nextdir-3)=1 and dirrection(nextdir-4)=2 and dirrection(nextdir-5)=-1 letter$="o" nextdir=1 goto donecheck endif endif if nextdir>=4 if dirrection(nextdir-1)=-2 and dirrection(nextdir-2)=1 and dirrection(nextdir-3)=2 and dirrection(nextdir-4)=-1 letter$="d" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=2 and dirrection(nextdir-2)=1 and dirrection(nextdir-3)=-2 and dirrection(nextdir-4)=2 letter$="h" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-1 and dirrection(nextdir-2)=2 and dirrection(nextdir-3)=1 and dirrection(nextdir-4)=-2 letter$="p" nextdir=1 goto donecheck endif endif if nextdir>=3 if -2=dirrection(nextdir-1) and 1=dirrection(nextdir-2) and 2=dirrection(nextdir-3) letter$="u" nextdir=1 goto donecheck endif if 2=dirrection(nextdir-1) and 1=dirrection(nextdir-2) and dirrection(nextdir-3)=-2 letter$="n" nextdir=1 goto donecheck endif if 1=dirrection(nextdir-1) and 2=dirrection(nextdir-2) and dirrection(nextdir-3)=-1 letter$="c" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=2 and dirrection(nextdir-2)=-1 and dirrection(nextdir-3)=-2 letter$="f" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=1 and dirrection(nextdir-2)=-3 and dirrection(nextdir-3)=1 letter$="z" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-2 and dirrection(nextdir-2)=-1 and dirrection(nextdir-3)=2 letter$="j" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-1 and dirrection(nextdir-2)=-2 and dirrection(nextdir-3)=2 letter$="t" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=1 and dirrection(nextdir-2)=-2 and dirrection(nextdir-3)=2 letter$="r" nextdir=1 goto donecheck endif endif if nextdir>=2 if dirrection(nextdir-1)=3 and dirrection(nextdir-2)=4 letter$="a" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=4 and dirrection(nextdir-2)=3 letter$="v" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=1 and dirrection(nextdir-2)=2 letter$="l" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=1 and dirrection(nextdir-2)=2 letter$="l" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=3 and dirrection(nextdir-2)=-3 letter$="k" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-2 and dirrection(nextdir-2)=-1 and len(sentence$)>0 sentence$=left$(sentence$,len(sentence$)-1) letter$="" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-2 and dirrection(nextdir-2)=1 letter$=" " nextdir=1 goto donecheck endif endif if dirrection(nextdir-1)=2 letter$="i" nextdir=1 goto donecheck endif if dirrection(nextdir-1)=-2 upercase=1 nextdir=1 goto back endif if dirrection(nextdir-1)=3 letter$="x" nextdir=1 goto donecheck endif goto back donecheck: if upercase=1 then letter$=upper$(letter$) sentence$=sentence$+letter$ upercase=0 back: return `make the letter buttons function button(name$,x,y) text x,y,name$ if mouseclick()=2 and mousex()>x and mousex()<x+text width(name$) and mousey()>y and mousey()<y+text height(name$) pressed=1 endif endfunction pressed `first set of instructions for printing in the pop-up window buttonpressed: if "a"=button$ then instructions$="up-right,down-right" if "b"=button$ then instructions$="down,up,right,down,left" if "c"=button$ then instructions$="left,down,right" if "d"=button$ then instructions$="left,down,right,up" if "e"=button$ then instructions$="right,up,left,down,right" if "f"=button$ then instructions$="up,left,down" if "g"=button$ then instructions$="left,down,right,up,down,left" if "h"=button$ then instructions$="down,up,right,down" if "i"=button$ then instructions$="down" if "j"=button$ then instructions$="down,left,up" if "k"=button$ then instructions$="down,up,right,down,left,down-right or down-left,down-right" if "l"=button$ then instructions$="down,right" if "m"=button$ then instructions$="down,up,right,down,up,right,down" if "n"=button$ then instructions$="up,right,down" if "o"=button$ then instructions$="left,down,right,up,left" if "p"=button$ then instructions$="up,right,down,left" if "q"=button$ then instructions$="left,down,right,up,down" if "r"=button$ then instructions$="down,up,right" if "s"=button$ then instructions$="left,down,right,down,left" if "t"=button$ then instructions$="down,up,left" if "u"=button$ then instructions$="down,right,up" if "v"=button$ then instructions$="down-right,up-right" if "w"=button$ then instructions$="down,right,up,down,right,up" if "x"=button$ then instructions$="down-right" if "y"=button$ then instructions$="down,right,up,down,left" if "z"=button$ then instructions$="right,down-left,right" return `second set of instructions for drawing only buttonpressed2: if "a"=button$ then instructions$="up-right,down-right" if "b"=button$ then instructions$="down,down,up,right,down,left" if "c"=button$ then instructions$="left,down,right" if "d"=button$ then instructions$="left,down,right,up,up" if "e"=button$ then instructions$="right,up,left,down,down,right" if "f"=button$ then instructions$="up,left,down,down" if "g"=button$ then instructions$="left,down,right,up,down,down,left" if "h"=button$ then instructions$="down,down,up,right,down" if "i"=button$ then instructions$="down" if "j"=button$ then instructions$="down,down,left,up" if "k"=button$ then instructions$="down,down,down,up,up,right,down,left,down-right" if "l"=button$ then instructions$="down,down,right" if "m"=button$ then instructions$="down,up,right,down,up,right,down" if "n"=button$ then instructions$="up,right,down" if "o"=button$ then instructions$="left,down,down,right,right,up,up,left" if "p"=button$ then instructions$="up,up,right,down,left" if "q"=button$ then instructions$="left,down,right,up,down,down" if "r"=button$ then instructions$="down,up,right" if "s"=button$ then instructions$="left,down,right,down,left" if "t"=button$ then instructions$="down,down,up,left" if "u"=button$ then instructions$="down,right,up" if "v"=button$ then instructions$="down-right,up-right" if "w"=button$ then instructions$="down,right,up,down,right,up" if "x"=button$ then instructions$="down-right" if "y"=button$ then instructions$="down,right,up,down,down,left" if "z"=button$ then instructions$="right,down-left,right" return `parses the second set of instructions to see what it should draw. drawit: comma=0 letterx=screen width()/2-80 lettery=screen height()/2 command$="" for k=1 to len(instructions$) a$=mid$(instructions$,k) if a$="," comma=comma+1 if command$="up" then command(comma)=1 if command$="down" then command(comma)=2 if command$="right" then command(comma)=3 if command$="left" then command(comma)=4 if command$="up-right" then command(comma)=5 if command$="down-right" then command(comma)=6 if command$="down-left" then command(comma)=7 if command$="up-left" then command(comma)=8 endif command$=command$+a$ if a$="," then command$="" next k comma=comma+1 if command$="up" then command(comma)=1 if command$="down" then command(comma)=2 if command$="right" then command(comma)=3 if command$="left" then command(comma)=4 if command$="up-right" then command(comma)=5 if command$="down-right" then command(comma)=6 if command$="down-left" then command(comma)=7 if command$="up-left" then command(comma)=8 for k=1 to comma if command(k)=1 for j=1 to 80 dot letterx,lettery letterx=letterx lettery=lettery-1 sync wait 10 next j endif if command(k)=2 for j=1 to 80 dot letterx,lettery letterx=letterx lettery=lettery+1 sync wait 10 next j endif if command(k)=3 for j=1 to 80 dot letterx,lettery letterx=letterx+1 lettery=lettery sync wait 10 next j endif if command(k)=4 for j=1 to 80 dot letterx,lettery letterx=letterx-1 lettery=lettery sync wait 10 next j endif if command(k)=5 for j=1 to 80 dot letterx,lettery letterx=letterx+1 lettery=lettery-1 sync wait 10 next j endif if command(k)=6 for j=1 to 80 dot letterx,lettery letterx=letterx+1 lettery=lettery+1 sync wait 10 next j endif if command(k)=7 for j=1 to 80 dot letterx,lettery letterx=letterx-1 lettery=lettery+1 sync wait 10 next j endif if command(k)=8 for j=1 to 80 dot letterx,lettery letterx=letterx-1 lettery=lettery-1 sync wait 10 next j endif next k return