1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? Function Key With INPUT

Discussion in 'Support' started by Joe Caverly, Dec 29, 2011.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
    Hi,
    I am using;

    Code:
    TCC  13.03.36   Windows XP [Version 5.1.2600]
    TCC Build 36   Windows XP Build 2600  Service Pack 3
    I am probably missing something simple, but am not having much success.

    My goal is to allow the entry of a name, but also the ability to branch if the F4 key is used. Here is my test code;

    Code:
    set thename=Hello
    input /E /K"[a-z][F4]" /L5 Enter a name: %%thename
    if %thename eq %@char[64 54 50] echo F4
    When I run this, I can enter a name, but it does not conclude the entry if I press the F4 function key. All I get is a beep. The only way to conclude the entry is to press the Enter key.

    How do I get it to recognize the F4 key? Again, I am probably missing something simple.

    A side note: In the help for INPUT it shows;

    Format: INPUT [/C /D /E["default"] /Ln /N /P /Wn /X] [prompt] %%varname

    there is no mention of the /K option, even though it is described elsewhere in the help for INPUT. When I do an INPUT /? from the console, I get;

    Code:
    INPUT [/C /D /E /K"keys" /Ln /N /P /Wn /X] [prompt ] %%varname
    These are not consistent with each other.

    Thanks from Joe
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,288
    Likes Received:
    39
    Makes sense to me. INPUT is intended to return a string of characters; function keys are not characters. If you want to allow the user to enter a string and also trap a function key, I think you'll need to roll your own using INKEY.
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,288
    Likes Received:
    39
    I answered too quickly. You can accept F-keys in INPUT by defining a keystroke alias:

    Code:
    alias @@F4=`^e*Abort*`
    set thename=Hello
    input /E /K"[a-z][F4]" /L5 Enter a name: %%thename
    if "%thename" eq "*Abort*" echo F4
    
    I had no idea that TCC would expand key macros inside INPUT like that!
     
  4. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
    Thankyou for that. It does indeed solve my problem. The help file for INPUT should be modified to indicate this method, since it presently says;

    Code:
    You can specify extended keys by enclosing their names in square brackets (within the quotes),  See Keys and Key Names for a complete listing of the key names you can use within the square brackets, and a description of the key name format.
    Thus, that is why I thought that the F4 key alone, as I had indicated, would allow me to exit the INPUT.

    Joe
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,885
    Likes Received:
    29
    Perhaps you could build something more flexible by looping around INKEY. For example,
    Code:
    UNSET key
    UNSET string
    INKEY /C /X %%key
    DO WHILE "%key" NE "@28" .AND. "%key" NE "@62"
        SET string=%[string]%key
        INKEY /C /X %%key
    ENDDO
    ECHO.
    IFF "%key" EQ "@28" THEN
        ECHO The string is %string
    ELSE
        ECHO Input aborted
    ENDIFF
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,808
    Likes Received:
    82
    INPUT will not return until you press enter (carriage return). That is not affected by anything you specify with /K. (The key alias Charles suggested sends an enter after the string substitution.)
     

Share This Page