Howdy, Stranger!

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

Categories

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.

cursor move

red3warlordred3warlord Posts: 77Member
how can i make the cursor move as the program runs by pressing keys on my keyboard?

Comments

  • zibadianzibadian Posts: 6,349Member
    : how can i make the cursor move as the program runs by pressing keys on my keyboard?
    :
    :
    You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
    [code]
    Set start x, y
    repeat
    GotoXY(X, Y);
    Readkey;
    case KeyRead of
    UpKey: decrease y position
    DownKey: increase y position
    LeftKey: decrease x position
    RightKey: increase x position
    end;
    until EndOfProgram;
    [/code]
    I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
  • red3warlordred3warlord Posts: 77Member
    [b][red]This message was edited by red3warlord at 2007-1-20 20:9:44[/red][/b][hr]
    : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
    : :
    : :
    : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
    : [code]
    : Set start x, y
    : repeat
    : GotoXY(X, Y);
    : Readkey;
    : case KeyRead of
    : UpKey: decrease y position
    : DownKey: increase y position
    : LeftKey: decrease x position
    : RightKey: increase x position
    : end;
    : until EndOfProgram;
    : [/code]
    : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
    :
    where should i declare it? in procedure or in the main body?


  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by red3warlord at 2007-1-20 20:9:44[/red][/b][hr]
    : : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
    : : :
    : : :
    : : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
    : : [code]
    : : Set start x, y
    : : repeat
    : : GotoXY(X, Y);
    : : Readkey;
    : : case KeyRead of
    : : UpKey: decrease y position
    : : DownKey: increase y position
    : : LeftKey: decrease x position
    : : RightKey: increase x position
    : : end;
    : : until EndOfProgram;
    : : [/code]
    : : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
    : :
    : where should i declare it? in procedure or in the main body?
    :
    :
    :
    I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.
  • red3warlordred3warlord Posts: 77Member
    : : [b][red]This message was edited by red3warlord at 2007-1-20 20:9:44[/red][/b][hr]
    : : : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
    : : : :
    : : : :
    : : : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
    : : : [code]
    : : : Set start x, y
    : : : repeat
    : : : GotoXY(X, Y);
    : : : Readkey;
    : : : case KeyRead of
    : : : UpKey: decrease y position
    : : : DownKey: increase y position
    : : : LeftKey: decrease x position
    : : : RightKey: increase x position
    : : : end;
    : : : until EndOfProgram;
    : : : [/code]
    : : : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
    : : :
    : : where should i declare it? in procedure or in the main body?
    : :
    : :
    : :
    : I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.
    :
    thank you for your help.... at least, my pain lessened down....
    so, how could i connect it to declare this code?
    is it a procedure or a function?


    from red3warlord with gratitude.....


  • zibadianzibadian Posts: 6,349Member
    : : : [b][red]This message was edited by red3warlord at 2007-1-20 20:9:44[/red][/b][hr]
    : : : : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
    : : : : :
    : : : : :
    : : : : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
    : : : : [code]
    : : : : Set start x, y
    : : : : repeat
    : : : : GotoXY(X, Y);
    : : : : Readkey;
    : : : : case KeyRead of
    : : : : UpKey: decrease y position
    : : : : DownKey: increase y position
    : : : : LeftKey: decrease x position
    : : : : RightKey: increase x position
    : : : : end;
    : : : : until EndOfProgram;
    : : : : [/code]
    : : : : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
    : : : :
    : : : where should i declare it? in procedure or in the main body?
    : : :
    : : :
    : : :
    : : [b]I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.[/b]
    : :
    : thank you for your help.... at least, my pain lessened down....
    : so, how could i connect it to declare this code?
    : is it a procedure or a function?
    :
    :
    : from red3warlord with gratitude.....
    :
    :
    :
    As I have said above it can be a procedure or the main program body. Only use a function if the code returns a clear result. Since this code doesn't return a result it shouldn't be a function.
  • red3warlordred3warlord Posts: 77Member
    : : : : [b][red]This message was edited by red3warlord at 2007-1-20 20:9:44[/red][/b][hr]
    : : : : : : how can i make the cursor move as the program runs by pressing keys on my keyboard?
    : : : : : :
    : : : : : :
    : : : : : You can use a repeat-until loop, ReadKey(), and GotoXY() for that. Here's the basic layout of the code:
    : : : : : [code]
    : : : : : Set start x, y
    : : : : : repeat
    : : : : : GotoXY(X, Y);
    : : : : : Readkey;
    : : : : : case KeyRead of
    : : : : : UpKey: decrease y position
    : : : : : DownKey: increase y position
    : : : : : LeftKey: decrease x position
    : : : : : RightKey: increase x position
    : : : : : end;
    : : : : : until EndOfProgram;
    : : : : : [/code]
    : : : : : I'll leave it to you to write this in the Pascal language. Read the descriptions of Readkey() in the help files, nearly all the other words are variables.
    : : : : :
    : : : : where should i declare it? in procedure or in the main body?
    : : : :
    : : : :
    : : : :
    : : : [b]I would make this the main body of the program. If you do you're starting to write an event-driven program. If this is only a part of the functionality of your program, then I would make this loop into a procedure.[/b]
    : : :
    : : thank you for your help.... at least, my pain lessened down....
    : : so, how could i connect it to declare this code?
    : : is it a procedure or a function?
    : :
    : :
    : : from red3warlord with gratitude.....
    : :
    : :
    : :
    : As I have said above it can be a procedure or the main program body. Only use a function if the code returns a clear result. Since this code doesn't return a result it shouldn't be a function.
    :
    now i get it....
    this had a very great revlevance of what my assignnment is!

    my instructor wanted me to make a program that will make the cursor move to a certain object, say for example, a character. when the cursor was moved to that character, it will look like a character with a textbackground.... how is it?
  • Phat NatPhat Nat Posts: 757Member
    : : As I have said above it can be a procedure or the main program body. Only use a function if the code returns a clear result. Since this code doesn't return a result it shouldn't be a function.
    : :
    : now i get it....
    : this had a very great revlevance of what my assignnment is!
    :
    : my instructor wanted me to make a program that will make the cursor move to a certain object, say for example, a character. when the cursor was moved to that character, it will look like a character with a textbackground.... how is it?
    :

    If this part of your assignment is just one section, then put it into a PROCEDURE, otherwise, just put it all into your main area.
    First off, I would make a procedure that displays your background. Whatever you want on the screen that does not change.
    Perhaps your screen will display something like this:
    [code]
    First Name: ____________ Last Name: ________________
    Age: ___ Birthdate: _______________

    1 12 20 31
    [/code]
    The numbers underneath wouldn't be shown, but are there to show that the first set of lines is diplayed 12 characters in and the second set of lines is 31 characters in. These are important. Also, we have two rows.

    So we would call our procedure to show this on the screen. This can either be in our main loop or just called once at the start. In our main loop, we would first want to fill in anything that would have been typed in. Use another procedure for this. I will call it ShowData.
    ShowData will just use four GotoXY() and Write() to write each variable (eg. FName,LName,Age,BirthDate) in the proper location.

    Next inside the loop you would want to display the cursor, then wait for a keypress and determine whether it is an arrow key or a letter/number. a CASE statement would work well here:
    [code]
    Key := Readkey;
    CASE Key Of
    #0 : Begin {Extended Keys aka Arrows/Function Keys/etc }
    Key := ReadKey;
    CASE Key Of
    #72 : If Y > 1 Then Y := Y - 1;
    #75 : If X > 1 Then X := X - 1;
    #77 : If X < 2 Then X := X + 1;
    #80 : If Y < 2 Then Y := Y + 1;
    End;
    End;
    #8 : If Length(CurrentStr) > 0 Then Delete(CurrentString,Length(CurrentStr),1);
    'A'..'Z',
    'a'..'z',
    '0'..'9' : CurrentStr := CurrentStr + Key;
    END;
    [/code]

    This would handle key input as well as arrow movement. When you display the cursor before this, you would just use GotoXY(12+X*19,Y+1);
    This way, when X = 0, 12+0*19=12, so your cursor would move to 12,Y+1 and when X = 1, 12+1*19=31, so your cursor would move to 31,Y+1. Note that this is where our two lines start on the screen (19 being the space between the start of the first and second set).

    From here, you would just use the STRING variable CurrentStr to set whatever variable is currently selected.
    For ease, I would recommend you just store all your String Variables into an array (in this case 2x2) so that you can just use X & Y to set the string.
    [code]
    VAR
    DataStr : Array[0..1,0..1] Of String; {0,0=FName 1,0=LName, 0,1=Age 1,1=B/D }
    [/code]
    Instead of the above lines, you would replace them with:
    [code]
    #8 : If Length(DataStr[X,Y]) > 0 Then Delete(DataStr[X,Y],Length(DataStr[X,Y]),1);
    'A'..'Z',
    'a'..'z',
    '0'..'9' : DataStr[X,Y] := DataStr[X,Y] + Key;
    [/code]

    Any questions, just ask,
    Phat Nat

Sign In or Register to comment.