Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
HELP~!! Can I read ESC? Posted by hl8 on 12 Jan 2005 at 5:07 AM
This message was edited by hl8 at 2005-1-12 5:22:24


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


Report
Re: HELP~!! Can I read ESC? Posted by hl8 on 12 Jan 2005 at 8:59 AM
: This message was edited by hl8 at 2005-1-12 5:22:24

:
: 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?
Report
Re: HELP~!! Can I read ESC? Posted by zibadian on 12 Jan 2005 at 9:45 AM
: : This message was edited by hl8 at 2005-1-12 5:22:24

: :
: : 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:
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;

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

Report
Re: HELP~!! Can I read ESC? Posted by hl8 on 13 Jan 2005 at 1:46 AM
This message was edited by hl8 at 2005-1-13 1:46:43

: : : This message was edited by hl8 at 2005-1-12 5:22:24

: : :
: : : 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:
:
: 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;
: 

: 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?


Report
Re: HELP~!! Can I read ESC? Posted by hl8 on 13 Jan 2005 at 3:58 AM
: This message was edited by hl8 at 2005-1-13 1:46:43

: : : : This message was edited by hl8 at 2005-1-12 5:22:24

: : : :
: : : : 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:
: :
: : 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;
: : 

: : 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?
:
:
:
     while KeyPressed do ReadKey; { Remove extended }

What is the use of this line??
I type this and it said "Invaild variable reference"...
Can I delete this line?
Report
Re: HELP~!! Can I read ESC? Posted by zibadian on 13 Jan 2005 at 5:44 AM
: : This message was edited by hl8 at 2005-1-13 1:46:43

: : : : : This message was edited by hl8 at 2005-1-12 5:22:24

: : : : :
: : : : : 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:
: : :
: : : 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;
: : : 

: : : 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?
: :
: :
: :
:
     while KeyPressed do ReadKey; { Remove extended }

: 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:
     while KeyPressed do ch := ReadKey; { Remove extended }

and add the ch variable as a local char variable.
Report
Re: HELP~!! Can I read ESC? Posted by zibadian on 13 Jan 2005 at 5:42 AM
: This message was edited by hl8 at 2005-1-13 1:46:43

: : : : This message was edited by hl8 at 2005-1-12 5:22:24

: : : :
: : : : 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:
: :
: : 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;
: : 

: : 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.
Report
Re: HELP~!! Can I read ESC? Posted by hl8 on 13 Jan 2005 at 8:43 AM
: : This message was edited by hl8 at 2005-1-13 1:46:43

: : : : : This message was edited by hl8 at 2005-1-12 5:22:24

: : : : :
: : : : : 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:
: : :
: : : 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;
: : : 

: : : 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~?
Report
Re: HELP~!! Can I read ESC? Posted by zibadian on 13 Jan 2005 at 8:55 AM
: : : This message was edited by hl8 at 2005-1-13 1:46:43

: : : : : : This message was edited by hl8 at 2005-1-12 5:22:24

: : : : : :
: : : : : : 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:
: : : :
: : : : 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;
: : : : 

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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.