[esc] in a textfield

BlitzPlus Forums/BlitzPlus Programming/[esc] in a textfield

CS_TBL(Posted 2004) [#1]
How do I read out an [esc] press while typing in a textfield ? :)

a$=RequestString$(256,256,80,24,"Blah!")
Notify a$
End


Function RequestString$(x,y,width,height,def$="")

	FlushEvents()
	FlushKeys()

	w=CreateWindow("",x,y,width,height,0,0)
	
	txt=CreateTextField(1,1,width-2,height-2,w)
	SetGadgetText txt,def$
	ActivateGadget txt
	Repeat
		WaitEvent()
		
		If EventID()=$803
			If EventSource()=w quit=True
		EndIf
		
		If EventSource()=txt
			If EventID()=$401
				If EventData()=13 ; enter
					quit=True
					returnstring$=TextFieldText(txt)
				EndIf
				If EventData()=27 ; esc
					End ; <-debug
					quit=True
					returnstring$=def$
				EndIf
			EndIf
		EndIf
	Until quit

	FreeGadget w	
	
	Return returnstring$
	
End Function



Eikon(Posted 2004) [#2]
Parent = CreateWindow("Escape", ClientWidth(Desktop())/2-90, ClientHeight(Desktop())/2-42, 180, 133, 0, 1)
Text1 = CreateTextField(5, 5, 163, 20, Parent, 0)
ActivateGadget Text1
in_Text = 1

HotKeyEvent 1, 0, $101, 15, 0, 0, 0, 0

Repeat
Select WaitEvent()
	Case $803
	End
	
	Case $101
	Select EventData()
		Case 15
		Notify "You pressed escape"

	End Select
.StepOut
End Select

Forever



Cold Harbour(Posted 2004) [#3]
Hey nice one Eikon, I was just trying to work out how to do that.


Eikon(Posted 2004) [#4]
Thanks h2so4. Study up on the HotKeyEvent, its very useful for things like this and tabbing between controls.