PDA

View Full Version : Getting text on a keypress



catventure
27-11-2005, 18:05
Hi,

What is the best way to GET text from a textbox after a <RETURN> keypress in the textbox?

In my attached example I've tried to do it using %WM_KEYDOWN and another method with %VK_RETURN - but didn't work.

If anyone cares to take a look, I'd be happy with your comments.

Cheers,
catventure

Petr Schreiber
27-11-2005, 18:17
Hi Catventure,

as usual, I have only "dirty" solution, but it works :)

The trick is following:
:arrow: Add to the dialog button, positioned at location, which cannot be viewed


%MY_SECRET_BUTTON
CONTROL ADD BUTTON, hDlg, %MY_SECRET_BUTTON, "", 10000, 10000, 20, 20, %BS_DEFAULT


... the %BS_DEFAULT makes ENTER to automatically click it


:arrow: In the windows message checking routine just add this :

CASE %WM_COMMAND
'Alternative try to get player input with <return> press
SELECT CASE wParam
CASE %MY_SECRET_BUTTON
'---If player hits <RETURN> get text and clear input textbox
IF GetAsyncKeyState&#40;%VK_RETURN&#41; <> 0 THEN
CONTROL GET TEXT hDlg,%ID_TEXTBOX TO tempstr
CONTROL SET TEXT hDlg,%ID_RICHEDIT,""
CONTROL SET TEXT hDlg,%ID_TEXTBOX,""
CONTROL SET TEXT hDlg,%ID_RICHEDIT," You typed&#58; " & tempstr
END IF
END SELECT


And the program starts to work !

Bye,
Psch

catventure
27-11-2005, 18:27
Psch,

Well done coming up with that :)
I'd forgotten of course about such sorcery!

I will try out the 'secret button' idea but am sure it must work better and more robustly than just capturing the keypress with getasynchkeystate as I attempted (which is a bit dodgy)

Thanks,


catventure