Results 1 to 3 of 3

Thread: Getting text on a keypress

  1. #1
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    587
    Blog Entries
    1
    Rep Power
    71

    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)
    TAB Forum - http://adventure.rpgdynasty.com/
    TAB Email Group - http://tech.groups.yahoo.com/group/TAB_IF_CREATOR/

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,828
    Blog Entries
    3
    Rep Power
    696

    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 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  3. #3
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    587
    Blog Entries
    1
    Rep Power
    71

    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)
    TAB Forum - http://adventure.rpgdynasty.com/
    TAB Email Group - http://tech.groups.yahoo.com/group/TAB_IF_CREATOR/

Posting Permissions

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