View Full Version : <ENTER> key problem
ErosOlmi
24-11-2006, 16:56
Hi catventure.
I had some time to play with <ENTER> key problem.
I've created an example you can find here attached in order to test the problem in details without all the complexity of T.A.B.
I've followed a different road compare to your code. Instead of using an hidden button, I'm using %WM_KEYDOWN message and wParam = 13 (<ENTER> key)
Please tell me if this method gives positive results to you or not.
I have to say that my method also fails in some cases under Win XP emitting a beep I'm not able to understand. I suppose in some cases the <ENTER> key goes lost in notification queue but I will investigate this later.
Let me know.
Eros
catventure
24-11-2006, 18:54
Good Afternoon Eros,
Nice example - and this does work very well on mine. :)
Sadly though, when incorporating the KEYDOWN test code into TAB Player and/or Editor instead of using invisible default button there is no apparent significant improvement or difference as far as I can tell...
It seems you may be indeed right and that the <enter> keypress gets lost sometimes in the loop, whereas other controls seem to respond OK.
Regards,
catventure.
ErosOlmi
24-11-2006, 19:03
Another way to trap <ENTER> key in a dialog is to trap Msg = %WM_COMMAND and wParam = 1
When <ENTER> is pressed a Msg = %WM_COMMAND and wParam = 1 is fired.
When <ESC> is pressed a Msg = %WM_COMMAND and wParam = 2 is fired.
I will try to study more T.A.B. to see if I can be more lucky
Eros
catventure
26-11-2006, 14:57
Hi Eros,
I noticed a user had made a post about trapping <enter> keypress in a textbox in Powerbasic forum... I don't understand it but just wondered iif you'd seen it or if it helps at all.
http://www.powerbasic.com/support/forums/Forum4/HTML/013919.html
catventure
catventure
27-02-2007, 11:37
Hi Eros,
With regard to this problem IBasicProfessional has a way of testing window controls for enter or tab keypress. I do not know if this can be made to work in thinBasic... It is similar to what you posted.
SETCONTROLNOTIFY
SETCONTROLNOTIFY win as WINDOW,id as INT,bTab as INT,bEnter as INT
Description
Turns control notification of enter and tab keys on or off.
Parameters
win - Window or dialog containing the control.
id - Control identifier.
bTab - TRUE to send @ENTABKEY notifications, FALSE otherwise.
bEnter- TRUE to send @ENENTERKEY notifications, FALSE otherwise.
Return value
None
Remarks
Designed for edit controls placed in a Window but will work with other controls as well. @ENTABKEY and @ENENTERKEY are special notification codes sent in @NOTIFYCODE when enabled. By default both are disabled for compatibility with older code and controls used in a dialog where the enter and TAB keys have a different meaning.
Example usage
WINDOW win
OPENWINDOW win,0,0,295,199,0,0,"Caption",&handler
CONTROL win,@EDIT,"Press Enter or TAB",83,39,124,27,0x50800000|@CTEDITAUTOH,5
SETFONT win,"Ariel",9,400,0,5
SETCONTROLNOTIFY(win,5,1,1)
SetFocus win,5
WAITUNTIL win=0
END
SUB handler
SELECT @MESSAGE
CASE @IDCONTROL
IF @CONTROLID = 5
SELECT @NOTIFYCODE
CASE @ENENTERKEY
MESSAGEBOX win,GetControlText(win,5),"Enter Pressed!"
SetFocus win,5
CASE @ENTABKEY
MESSAGEBOX win,"Tab key pressed","Info"
SetFocus win,5
ENDSELECT
ENDIF
CASE @IDCREATE
CENTERWINDOW win
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
ENDSELECT
RETURN
ENDSUB
Best wishes,
catventure
Petr Schreiber
27-02-2007, 11:45
Hi Catventure,
I don't remember the reason why we used the secret button way, but try to use just:
IF getwindowkeystate( hWnd, %VK_RETURN) and gameloaded = 1 THEN
'---turn off sizing while text being output
sizerich = 2
MENU SET STATE hMenu, 1, %MF_DISABLED
MENU SET STATE hMenu, 2, %MF_DISABLED
'---If player hits <RETURN> get their inputted text and clear input textbox
CONTROL GET TEXT hwnd, %ID_TEXTBOX2 TO tempstr
CONTROL SET TEXT hwnd, %ID_TEXTBOX2, ""
getuserinput
DO UNTIL tempstr = ""
parser
responsetable
IF tabtemp = 1 THEN
EXIT DO
END IF
tabletwo
resetvars
charmovement
LOOP
tabtemp = 0
IF gameloaded = 1 THEN
resetvars
promptforinput
GETWINDOWKEYSTATE( hwnd, %VK_RETURN )
END IF
END IF
...instead of trying to catch %MY_SECRET_BUTTON press, it works lightning fast !
So just move the code above before the SELECT CASE Msg.
Bye,
Petr
Petr Schreiber
27-02-2007, 11:48
Hi,
please find here modified Player and see how fast it is
Bye,
Petr
catventure
27-02-2007, 12:19
WhooHey!!!!!!!!!!!!!!!!!!!!!!!!!
Congratulations Petr, you have solved it!!!
Enter key now works instantaneously in both Editor and Player.
Good work and well done. I just could not figure it.
The game will now play far smoother, better and respond correctly without sluggish delay. A great and fantastic solution. We will now know in future how to do capture of <enter> in editbox.
Many, many thanks.
catventure.
Petr Schreiber
27-02-2007, 14:26
Hi,
I am happy it works for you.
I wonder why we did not see this solution sooner :)
Bye,
Petr
ErosOlmi
27-02-2007, 15:31
Maybe you do not know but <ENTER> key has been my nightmare for long time.
But now is seems over. THANK YOU Petr.
Eros