Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Arrow Keys #

NinthAngleNinthAngle Posts: 98Member
I am trying to modify a program I wrote to display a new image every time the user presses the left or right arrow key. What is the readkey number for these keys?

thx
NA

Comments

  • zibadianzibadian Posts: 6,349Member
    : I am trying to modify a program I wrote to display a new image every time the user presses the left or right arrow key. What is the readkey number for these keys?
    :
    : thx
    : NA
    :
    Try this code:
    [code]
    repeat
    ch := ReadKey;
    if ch = #0 then
    Writeln('Extended key: ', Byte(ReadKey))
    else
    Writeln('Normal key: ', Byte(ch));
    until ch = #13; { enter }
    [/code]
    I know that they are extended keys, but cannot remember the second code.
  • PP2005PP2005 Posts: 111Member
    These are the secondary codes for the arrow keys:

    72: Up arrow
    75: Left arrow
    77: Right arrow
    80: Down arrow
  • acidicburnacidicburn Posts: 8Member
    #72 = up
    #80 = down
    #75 = left
    #78 = right
  • NinthAngleNinthAngle Posts: 98Member
    : #72 = up
    : #80 = down
    : #75 = left
    : #78 = right
    :

    Can you tell me what the numbers for "." and "," are? Is there perhaps a chart for all key numbers?
  • acidicburnacidicburn Posts: 8Member
    : : #72 = up
    : : #80 = down
    : : #75 = left
    : : #78 = right
    : :
    :
    : Can you tell me what the numbers for "." and "," are? Is there perhaps a chart for all key numbers?
    :
    http://www.lookuptables.com/
  • zibadianzibadian Posts: 6,349Member
    : : : #72 = up
    : : : #80 = down
    : : : #75 = left
    : : : #78 = right
    : : :
    : :
    : : Can you tell me what the numbers for "." and "," are? Is there perhaps a chart for all key numbers?
    : :
    : http://www.lookuptables.com/
    :
    The code I gave you can give you all the numbers by running it.
  • king0deuking0deu Posts: 29Member
    [b][red]This message was edited by king0deu at 2006-10-30 9:25:55[/red][/b][hr]
    [b][red]This message was edited by king0deu at 2006-10-30 9:22:15[/red][/b][hr]
    : : I am trying to modify a program I wrote to display a new image every time the user presses the left or right arrow key. What is the readkey number for these keys?
    : :
    : : thx
    : : NA
    : :
    : Try this code:
    : [code]
    : repeat
    : ch := ReadKey;
    : if ch = #0 then
    : Writeln('Extended key: ', Byte(ReadKey))
    : else
    : Writeln('Normal key: ', Byte(ch));
    : until ch = #13; { enter }
    : [/code]
    : I know that they are extended keys, but cannot remember the second code.
    :

    in your code there's a function called "byte", could you tell me what it does? I don't see it anywhere

    And one more problem: I'm confused with that readkey function
    In the code above, if I change it to this:

    [code]
    ...
    ch:=readkey;
    writeln(byte(readkey));
    writeln(byte(ch);
    ...
    [/code]

    then, when you run it, if you press a normal key (e.g "a" or space), you must press two times (it's likely the readkey function was called twice)
    and the result is:

    32
    97

    And if you press an extended key (let it be right arrow), the result is:

    77
    0

    so explain it to me, I'm confused


  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by king0deu at 2006-10-30 9:25:55[/red][/b][hr]
    : [b][red]This message was edited by king0deu at 2006-10-30 9:22:15[/red][/b][hr]
    : : : I am trying to modify a program I wrote to display a new image every time the user presses the left or right arrow key. What is the readkey number for these keys?
    : : :
    : : : thx
    : : : NA
    : : :
    : : Try this code:
    : : [code]
    : : repeat
    : : ch := ReadKey;
    : : if ch = #0 then
    : : Writeln('Extended key: ', Byte(ReadKey))
    : : else
    : : Writeln('Normal key: ', Byte(ch));
    : : until ch = #13; { enter }
    : : [/code]
    : : I know that they are extended keys, but cannot remember the second code.
    : :
    :
    : in your code there's a function called "byte", could you tell me what it does? I don't see it anywhere
    :
    : And one more problem: I'm confused with that readkey function
    : In the code above, if I change it to this:
    :
    : [code]
    : ...
    : ch:=readkey;
    : writeln(byte(readkey));
    : writeln(byte(ch);
    : ...
    : [/code]
    :
    : then, when you run it, if you press a normal key (e.g "a" or space), you must press two times (it's likely the readkey function was called twice)
    : and the result is:
    :
    : 32
    : 97
    :
    : And if you press an extended key (let it be right arrow), the result is:
    :
    : 77
    : 0
    :
    : so explain it to me, I'm confused
    :
    :
    :
    The word byte is in this case not a function, but a type-cast. I tell the compiler that the char variable should be used as a byte.
    The "normal" keys fall within the ASCII character-set, while the extended keys always have 2 bytes: #0 (zero char, not character "0") and another character. Since you cannot press the #0 key (it does not exist on keyboards) any #0 result from readkey means that the user pressed an extended key. Hence the second readkey. Examples:
    - If the user presses "a" (#97), then ch = #0 will return false. Thus the value of ch is shown as a number (byte type-casting)
    - If the user presses the up-array (#0 #72), then ch = #0 will return true. Thus the second byte of the keypress is read by the second readkey, and that value is shown.
    This shows why the if-then statement is so important.
Sign In or Register to comment.