Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Function Key With INPUT

Aug
1,917
68
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
 
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.
 
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!
 
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!

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
 
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
 
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.

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.)
 

Similar threads

Back
Top