Page 1 of 1

Realtime Chat Input

Posted: Thu Jan 18, 2007 9:04 am
by kawasaki
In games like Half Life 2: Deathmatch, or any other multiplayer game, you can press a key combination to enter text, to send to other players... How do i go about updating a string with new keys entered, and control for backspace etc...

Ive tried using a thread with the following code (partial), but it crashes for some reason...

Code: Select all

Procedure ControlInput(a)

Repeat
ExamineKeyboard()
In$=KeyboardInkey()
If In$
TextInput$+In$
Debug In$
If KeyboardReleased(#PB_Key_Delete)
TextInput$=Left(TextInput$,Len(TextInput$)-1)
EndIf
EndIf

Until KeyboardPushed(#PB_Key_Return)
AddChat(UCase(Username)+": "+TextInput$,1)
Chat=0
Keylock=0
TextInput$=""
EndProcedure
This function is called into a seperate thread when Control + C are pressed on the kryboard... "AddChat" points to another procedure which runs fine.

The Examine keyboard only runs once, either in the main loop or in this loop, depending on the value KeyLock.

Any suggestions?

Thanks

Mike

Posted: Thu Jan 18, 2007 10:36 am
by Derek
You need a window event handler in your loop.

Try putting

e=windowevent()

after your repeat command. The program is getting bogged down with all the events that are being dealt with.

Posted: Thu Jan 18, 2007 10:49 am
by Derek
Also, I would change the KeyboardReleased(#PB_Key_Delete) to KeyboardReleased(#PB_Key_Back) or at least include both.

Most people use the backspace key to delete. :)

Posted: Thu Jan 18, 2007 6:22 pm
by kawasaki
Thanks :D

Posted: Thu Jan 18, 2007 8:53 pm
by Derek
That's ok