Results 1 to 3 of 3

Thread: Getting text on a keypress

  1. #1

    Getting text on a keypress

    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
    Attached Files Attached Files
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Getting text on a keypress

    Hi Catventure,

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

    The trick is following:
    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


    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    Getting text on a keypress

    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
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •