HELP~!! Can I read ESC? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP~!! Can I read ESC?

hl8hl8 Posts: 14Member
[b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]

I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
Can I use readkey?


Comments

  • hl8hl8 Posts: 14Member
    : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    :
    : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : Can I use readkey?
    :
    :
    :
    When I use readkey, can I display the input at the same time?
  • zibadianzibadian Posts: 6,349Member
    : : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    : :
    : : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : : Can I use readkey?
    : :
    : :
    : :
    : When I use readkey, can I display the input at the same time?
    :
    The escape-key is represented by the #27 char. You can use ReadKey and display the input at the same time. Here is a function, which you can use:
    [code]
    function ReadText(const X, Y: integer): string;
    { This is a blocking user entry function based on readkey
    Handles the following key-strokes:
    - Backspace: removes last character
    - Enter: Sets the result to true
    - ASCII Code 32 (space) and upwards are valid characters
    - Removes extended (multi-byte) keypresses
    Other features:
    - positions the input field at X, Y relative to top-left of the screen
    }
    var
    UserInput: string;
    begin
    UserText := '';
    repeat
    ch := ReadKey; { Get the ASCII key code }
    case ch of
    #0..#7: ;
    #8: Delete(UserInput, Length(UserInput), 1);
    #9..#31: ;
    else UserInput := UserInput + ch;
    end;
    while KeyPressed do ReadKey; { Remove extended }
    GotoXY(X, Y); { Show the result at X, Y }
    write(UserInput);
    until ch = #27;
    ReadText := UserInput;
    end;
    [/code]
    This function ends if the user presses the ENTER key. If you need the non-blocking variant of this function check out this message: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=287056&Setting=A0003F2002

  • hl8hl8 Posts: 14Member
    [b][red]This message was edited by hl8 at 2005-1-13 1:46:43[/red][/b][hr]
    : : : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    : : :
    : : : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : : : Can I use readkey?
    : : :
    : : :
    : : :
    : : When I use readkey, can I display the input at the same time?
    : :
    : The escape-key is represented by the #27 char. You can use ReadKey and display the input at the same time. Here is a function, which you can use:
    : [code]
    : function ReadText(const X, Y: integer): string;
    : { This is a blocking user entry function based on readkey
    : Handles the following key-strokes:
    : - Backspace: removes last character
    : - Enter: Sets the result to true
    : - ASCII Code 32 (space) and upwards are valid characters
    : - Removes extended (multi-byte) keypresses
    : Other features:
    : - positions the input field at X, Y relative to top-left of the screen
    : }
    : var
    : UserInput: string;
    : begin
    : UserText := '';
    : repeat
    : ch := ReadKey; { Get the ASCII key code }
    : case ch of
    : #0..#7: ;
    : #8: Delete(UserInput, Length(UserInput), 1);
    : #9..#31: ;
    : else UserInput := UserInput + ch;
    : end;
    : while KeyPressed do ReadKey; { Remove extended }
    : GotoXY(X, Y); { Show the result at X, Y }
    : write(UserInput);
    : until ch = #27;
    : ReadText := UserInput;
    : end;
    : [/code]
    : This function ends if the user presses the ENTER key. If you need the non-blocking variant of this function check out this message: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=287056&Setting=A0003F2002
    :
    :
    Thank you very much!! Your code is very useful~! ^o^

    By the way, I also want to ask about the Delay function. Is the time delayed various using different CPU?


  • hl8hl8 Posts: 14Member
    : [b][red]This message was edited by hl8 at 2005-1-13 1:46:43[/red][/b][hr]
    : : : : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    : : : :
    : : : : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : : : : Can I use readkey?
    : : : :
    : : : :
    : : : :
    : : : When I use readkey, can I display the input at the same time?
    : : :
    : : The escape-key is represented by the #27 char. You can use ReadKey and display the input at the same time. Here is a function, which you can use:
    : : [code]
    : : function ReadText(const X, Y: integer): string;
    : : { This is a blocking user entry function based on readkey
    : : Handles the following key-strokes:
    : : - Backspace: removes last character
    : : - Enter: Sets the result to true
    : : - ASCII Code 32 (space) and upwards are valid characters
    : : - Removes extended (multi-byte) keypresses
    : : Other features:
    : : - positions the input field at X, Y relative to top-left of the screen
    : : }
    : : var
    : : UserInput: string;
    : : begin
    : : UserText := '';
    : : repeat
    : : ch := ReadKey; { Get the ASCII key code }
    : : case ch of
    : : #0..#7: ;
    : : #8: Delete(UserInput, Length(UserInput), 1);
    : : #9..#31: ;
    : : else UserInput := UserInput + ch;
    : : end;
    : : while KeyPressed do ReadKey; { Remove extended }
    : : GotoXY(X, Y); { Show the result at X, Y }
    : : write(UserInput);
    : : until ch = #27;
    : : ReadText := UserInput;
    : : end;
    : : [/code]
    : : This function ends if the user presses the ENTER key. If you need the non-blocking variant of this function check out this message: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=287056&Setting=A0003F2002
    : :
    : :
    : Thank you very much!! Your code is very useful~! ^o^
    :
    : By the way, I also want to ask about the Delay function. Is the time delayed various using different CPU?
    :
    :
    :
    [code] while KeyPressed do ReadKey; { Remove extended }[/code]
    What is the use of this line??
    I type this and it said "Invaild variable reference"...
    Can I delete this line?
  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by hl8 at 2005-1-13 1:46:43[/red][/b][hr]
    : : : : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    : : : :
    : : : : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : : : : Can I use readkey?
    : : : :
    : : : :
    : : : :
    : : : When I use readkey, can I display the input at the same time?
    : : :
    : : The escape-key is represented by the #27 char. You can use ReadKey and display the input at the same time. Here is a function, which you can use:
    : : [code]
    : : function ReadText(const X, Y: integer): string;
    : : { This is a blocking user entry function based on readkey
    : : Handles the following key-strokes:
    : : - Backspace: removes last character
    : : - Enter: Sets the result to true
    : : - ASCII Code 32 (space) and upwards are valid characters
    : : - Removes extended (multi-byte) keypresses
    : : Other features:
    : : - positions the input field at X, Y relative to top-left of the screen
    : : }
    : : var
    : : UserInput: string;
    : : begin
    : : UserText := '';
    : : repeat
    : : ch := ReadKey; { Get the ASCII key code }
    : : case ch of
    : : #0..#7: ;
    : : #8: Delete(UserInput, Length(UserInput), 1);
    : : #9..#31: ;
    : : else UserInput := UserInput + ch;
    : : end;
    : : while KeyPressed do ReadKey; { Remove extended }
    : : GotoXY(X, Y); { Show the result at X, Y }
    : : write(UserInput);
    : : until ch = #27;
    : : ReadText := UserInput;
    : : end;
    : : [/code]
    : : This function ends if the user presses the ENTER key. If you need the non-blocking variant of this function check out this message: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=287056&Setting=A0003F2002
    : :
    : :
    : Thank you very much!! Your code is very useful~! ^o^
    :
    : By the way, I also want to ask about the Delay function. Is the time delayed various using different CPU?
    :
    :
    :
    Delay() is not CPU dependent, but will not work for very small values.
  • zibadianzibadian Posts: 6,349Member
    : : [b][red]This message was edited by hl8 at 2005-1-13 1:46:43[/red][/b][hr]
    : : : : : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    : : : : :
    : : : : : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : : : : : Can I use readkey?
    : : : : :
    : : : : :
    : : : : :
    : : : : When I use readkey, can I display the input at the same time?
    : : : :
    : : : The escape-key is represented by the #27 char. You can use ReadKey and display the input at the same time. Here is a function, which you can use:
    : : : [code]
    : : : function ReadText(const X, Y: integer): string;
    : : : { This is a blocking user entry function based on readkey
    : : : Handles the following key-strokes:
    : : : - Backspace: removes last character
    : : : - Enter: Sets the result to true
    : : : - ASCII Code 32 (space) and upwards are valid characters
    : : : - Removes extended (multi-byte) keypresses
    : : : Other features:
    : : : - positions the input field at X, Y relative to top-left of the screen
    : : : }
    : : : var
    : : : UserInput: string;
    : : : begin
    : : : UserText := '';
    : : : repeat
    : : : ch := ReadKey; { Get the ASCII key code }
    : : : case ch of
    : : : #0..#7: ;
    : : : #8: Delete(UserInput, Length(UserInput), 1);
    : : : #9..#31: ;
    : : : else UserInput := UserInput + ch;
    : : : end;
    : : : while KeyPressed do ReadKey; { Remove extended }
    : : : GotoXY(X, Y); { Show the result at X, Y }
    : : : write(UserInput);
    : : : until ch = #27;
    : : : ReadText := UserInput;
    : : : end;
    : : : [/code]
    : : : This function ends if the user presses the ENTER key. If you need the non-blocking variant of this function check out this message: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=287056&Setting=A0003F2002
    : : :
    : : :
    : : Thank you very much!! Your code is very useful~! ^o^
    : :
    : : By the way, I also want to ask about the Delay function. Is the time delayed various using different CPU?
    : :
    : :
    : :
    : [code] while KeyPressed do ReadKey; { Remove extended }[/code]
    : What is the use of this line??
    : I type this and it said "Invaild variable reference"...
    : Can I delete this line?
    :
    Sevral keys like function keys use 2-bytes to identify themselves. These bytes must be removed, otherwise the user will appear to have pressed 2 keys, while only pressing 1. The line above removes those keys. To solve tghis problem, change it to this:
    [code] while KeyPressed do ch := ReadKey; { Remove extended }[/code]
    and add the ch variable as a local char variable.
  • hl8hl8 Posts: 14Member
    : : [b][red]This message was edited by hl8 at 2005-1-13 1:46:43[/red][/b][hr]
    : : : : : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    : : : : :
    : : : : : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : : : : : Can I use readkey?
    : : : : :
    : : : : :
    : : : : :
    : : : : When I use readkey, can I display the input at the same time?
    : : : :
    : : : The escape-key is represented by the #27 char. You can use ReadKey and display the input at the same time. Here is a function, which you can use:
    : : : [code]
    : : : function ReadText(const X, Y: integer): string;
    : : : { This is a blocking user entry function based on readkey
    : : : Handles the following key-strokes:
    : : : - Backspace: removes last character
    : : : - Enter: Sets the result to true
    : : : - ASCII Code 32 (space) and upwards are valid characters
    : : : - Removes extended (multi-byte) keypresses
    : : : Other features:
    : : : - positions the input field at X, Y relative to top-left of the screen
    : : : }
    : : : var
    : : : UserInput: string;
    : : : begin
    : : : UserText := '';
    : : : repeat
    : : : ch := ReadKey; { Get the ASCII key code }
    : : : case ch of
    : : : #0..#7: ;
    : : : #8: Delete(UserInput, Length(UserInput), 1);
    : : : #9..#31: ;
    : : : else UserInput := UserInput + ch;
    : : : end;
    : : : while KeyPressed do ReadKey; { Remove extended }
    : : : GotoXY(X, Y); { Show the result at X, Y }
    : : : write(UserInput);
    : : : until ch = #27;
    : : : ReadText := UserInput;
    : : : end;
    : : : [/code]
    : : : This function ends if the user presses the ENTER key. If you need the non-blocking variant of this function check out this message: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=287056&Setting=A0003F2002
    : : :
    : : :
    : : Thank you very much!! Your code is very useful~! ^o^
    : :
    : : By the way, I also want to ask about the Delay function. Is the time delayed various using different CPU?
    : :
    : :
    : :
    : Delay() is not CPU dependent, but will not work for very small values.
    :

    for my computer, I use for i:=1 to 100 do delay(65535); for 10 seconds.
    But for my friend's, she only use delay is enough.... Why is that~?
  • zibadianzibadian Posts: 6,349Member
    : : : [b][red]This message was edited by hl8 at 2005-1-13 1:46:43[/red][/b][hr]
    : : : : : : [b][red]This message was edited by hl8 at 2005-1-12 5:22:24[/red][/b][hr]
    : : : : : :
    : : : : : : I am reading a string or an integer[involve 2 digit~!], can the user quit by pressing ESC?
    : : : : : : Can I use readkey?
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : : When I use readkey, can I display the input at the same time?
    : : : : :
    : : : : The escape-key is represented by the #27 char. You can use ReadKey and display the input at the same time. Here is a function, which you can use:
    : : : : [code]
    : : : : function ReadText(const X, Y: integer): string;
    : : : : { This is a blocking user entry function based on readkey
    : : : : Handles the following key-strokes:
    : : : : - Backspace: removes last character
    : : : : - Enter: Sets the result to true
    : : : : - ASCII Code 32 (space) and upwards are valid characters
    : : : : - Removes extended (multi-byte) keypresses
    : : : : Other features:
    : : : : - positions the input field at X, Y relative to top-left of the screen
    : : : : }
    : : : : var
    : : : : UserInput: string;
    : : : : begin
    : : : : UserText := '';
    : : : : repeat
    : : : : ch := ReadKey; { Get the ASCII key code }
    : : : : case ch of
    : : : : #0..#7: ;
    : : : : #8: Delete(UserInput, Length(UserInput), 1);
    : : : : #9..#31: ;
    : : : : else UserInput := UserInput + ch;
    : : : : end;
    : : : : while KeyPressed do ReadKey; { Remove extended }
    : : : : GotoXY(X, Y); { Show the result at X, Y }
    : : : : write(UserInput);
    : : : : until ch = #27;
    : : : : ReadText := UserInput;
    : : : : end;
    : : : : [/code]
    : : : : This function ends if the user presses the ENTER key. If you need the non-blocking variant of this function check out this message: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=287056&Setting=A0003F2002
    : : : :
    : : : :
    : : : Thank you very much!! Your code is very useful~! ^o^
    : : :
    : : : By the way, I also want to ask about the Delay function. Is the time delayed various using different CPU?
    : : :
    : : :
    : : :
    : : Delay() is not CPU dependent, but will not work for very small values.
    : :
    :
    : for my computer, I use for i:=1 to 100 do delay(65535); for 10 seconds.
    : But for my friend's, she only use delay is enough.... Why is that~?
    :
    Probabaly differences between windows and dos, although I have never heard of it. Your loop should wait for 6500 seconds or around 1 hour and 50 minutes instead of 10 seconds.
Sign In or Register to comment.