Character In Text Area

BlitzPlus Forums/BlitzPlus Programming/Character In Text Area

MattVonFat(Posted 2004) [#1]
How would i detect which character has just been typed in a text area?


Eikon(Posted 2004) [#2]
Monitor TextAreaText
http://www.blitzbasic.com/bpdocs/command.php?name=TextAreaText&ref=gui_cat


MattVonFat(Posted 2004) [#3]
Thanks, but i need to record the keystroke in the text area as they type it so that for example if they typed e as they pressed it, it opened a notify box. I tried KeyHit() but that doesnt work when youre in a textarea.


Eikon(Posted 2004) [#4]
I meant you could Monitor the TextAreaText like this:
DeskW = ClientWidth(Desktop())
DeskH = ClientHeight(Desktop())

Parent    = CreateWindow("TextArea Text Monitor Example", DeskW/2-320, DeskH/2-240, 640, 480, 0, 1)
TextBox   = CreateTextArea(1, 20, 632, 434, Parent, 1)

TextMon   = CreateTimer(100) ; 100ms
AreaText$ = ""               ; Area Text

Repeat

Select WaitEvent()
	Case $803
	End
	
	Case $4001 ; Tick
	Select EventSource()
		Case TextMon
		tmp$ = TextAreaText$(TextBox) ; Grab Text
		If tmp$ <> AreaText$ Then ; User has entered a character
			tmp2$ = Right(tmp$, Len(tmp$) - Len(AreaText$)) ; Isolate new from old entry
			If Instr(Lower(tmp2$), "e", 1) Then Notify "You entered an 'e'"
			AreaText$ = tmp$
		EndIf
		
	End Select

End Select

Forever

This will notify the user when they enter a lower or uppercase letter e.


MattVonFat(Posted 2004) [#5]
Thanks for that. It's perfect!