readkey does not work in VGA mode. Help me please!

I've written a paddle game in a VGA window in Dev-Pascal. It perfectly works when i set a computer playing vs another one, but when I try to make it respond to keypresses nothing happens. my code is like this:

var c:char;

while c <> 'q' do
begin

if keypressed then
begin

c := readkey;
if c = chr(72) then { chr(72) stands for up arrow i think }
begin

y := y -1;

end;
end;
end;

I've seen it work on compilators like Free Pascal, but why doesn't it work in Dev-Pascal? Is there anything I can do to fix this?

Comments

  • : I've written a paddle game in a VGA window in Dev-Pascal. It perfectly works when i set a computer playing vs another one, but when I try to make it respond to keypresses nothing happens. my code is like this:
    :
    : var c:char;
    :
    : while c <> 'q' do
    : begin
    :
    : if keypressed then
    : begin
    :
    : c := readkey;
    : if c = chr(72) then { chr(72) stands for up arrow i think }
    : begin
    :
    : y := y -1;
    :
    : end;
    : end;
    : end;
    :
    : I've seen it work on compilators like Free Pascal, but why doesn't it work in Dev-Pascal? Is there anything I can do to fix this?


    DevPascal is just an IDE, it actually uses the Free Pascal compiler. So what do you mean by a "VGA Window"? You mean an actual Windows form? If so, you have to do it a different way than using KeyPressed and ReadKey. If you don't mean a Windows form, what do you mean?
  • : I've written a paddle game in a VGA window in Dev-Pascal. It perfectly works when i set a computer playing vs another one, but when I try to make it respond to keypresses nothing happens. my code is like this:
    :
    : var c:char;
    :
    : while c <> 'q' do
    : begin
    :
    : if keypressed then
    : begin
    :
    : c := readkey;
    : if c = chr(72) then { chr(72) stands for up arrow i think }
    : begin
    :
    : y := y -1;
    :
    : end;
    : end;
    : end;
    :
    : I've seen it work on compilators like Free Pascal, but why doesn't it work in Dev-Pascal? Is there anything I can do to fix this?
    :

    You might not have trapped the up arrow key.
    Try this :
    --------
    C := ReadKey;
    If C = #0 then C := ReadKey;
    --------
    This should get you almost all the keys.
  • [b][red]This message was edited by emilo35 at 2004-10-17 8:21:49[/red][/b][hr]
    : : I've written a paddle game in a VGA window in Dev-Pascal. It perfectly works when i set a computer playing vs another one, but when I try to make it respond to keypresses nothing happens. my code is like this:
    : :
    : : var c:char;
    : :
    : : while c <> 'q' do
    : : begin
    : :
    : : if keypressed then
    : : begin
    : :
    : : c := readkey;
    : : if c = chr(72) then { chr(72) stands for up arrow i think }
    : : begin
    : :
    : : y := y -1;
    : :
    : : end;
    : : end;
    : : end;
    : :
    : : I've seen it work on compilators like Free Pascal, but why doesn't it work in Dev-Pascal? Is there anything I can do to fix this?
    : :
    :
    : You might not have trapped the up arrow key.
    : Try this :
    : --------
    : C := ReadKey;
    : If C = #0 then C := ReadKey;
    : --------
    : This should get you almost all the keys.
    :

    But I think that the whole "if keypressed then" thing is corrupt. I made a test program to see if it worked, something like;

    while not keypressed do
    begin
    inc(x);
    putpixel(getmaxy div 2, x,white);
    delay(50);
    end;

    But when i ran the prgoram, the pixel continued to move though I pressed all the buttons on my keyboard..

    And to Manning; I'm using a console application. VGA means graph mode in DOS, right?



  • : [b][red]This message was edited by emilo35 at 2004-10-17 8:21:49[/red][/b][hr]
    : : : I've written a paddle game in a VGA window in Dev-Pascal. It perfectly works when i set a computer playing vs another one, but when I try to make it respond to keypresses nothing happens. my code is like this:
    : : :
    : : : var c:char;
    : : :
    : : : while c <> 'q' do
    : : : begin
    : : :
    : : : if keypressed then
    : : : begin
    : : :
    : : : c := readkey;
    : : : if c = chr(72) then { chr(72) stands for up arrow i think }
    : : : begin
    : : :
    : : : y := y -1;
    : : :
    : : : end;
    : : : end;
    : : : end;
    : : :
    : : : I've seen it work on compilators like Free Pascal, but why doesn't it work in Dev-Pascal? Is there anything I can do to fix this?
    : : :
    : :
    : : You might not have trapped the up arrow key.
    : : Try this :
    : : --------
    : : C := ReadKey;
    : : If C = #0 then C := ReadKey;
    : : --------
    : : This should get you almost all the keys.
    : :
    :
    : But I think that the whole "if keypressed then" thing is corrupt. I made a test program to see if it worked, something like;
    :
    : while not keypressed do
    : begin
    : inc(x);
    : putpixel(getmaxy div 2, x,white);
    : delay(50);
    : end;
    :
    : But when i ran the prgoram, the pixel continued to move though I pressed all the buttons on my keyboard..
    :
    : And to Manning; I'm using a console application. VGA means graph mode in DOS, right?
    :
    Ok, are you saying you want the pixel to move only if press the up arrow key? The code you have above says that while no key has been pressed, the pixel will still move. Only when when you press a key, the pixel doesn't move, but because there is no delay outside of the while loop, you can't see it.
  • : : But I think that the whole "if keypressed then" thing is corrupt. I made a test program to see if it worked, something like;
    : :
    : : while not keypressed do
    : : begin
    : : inc(x);
    : : putpixel(getmaxy div 2, x,white);
    : : delay(50);
    : : end;
    : :
    : : But when i ran the prgoram, the pixel continued to move though I pressed all the buttons on my keyboard..
    : :
    : : And to Manning; I'm using a console application. VGA means graph mode in DOS, right?
    : :
    : Ok, are you saying you want the pixel to move only if press the up arrow key? The code you have above says that while no key has been pressed, the pixel will still move. Only when when you press a key, the pixel doesn't move, but because there is no delay outside of the while loop, you can't see it.
    :

    Well, it's the only loop in the program, so it should shut down when I press a key.

  • : : : But I think that the whole "if keypressed then" thing is corrupt. I made a test program to see if it worked, something like;
    : : :
    : : : while not keypressed do
    : : : begin
    : : : inc(x);
    : : : putpixel(getmaxy div 2, x,white);
    : : : delay(50);
    : : : end;
    : : :
    : : : But when i ran the prgoram, the pixel continued to move though I pressed all the buttons on my keyboard..
    : : :
    : : : And to Manning; I'm using a console application. VGA means graph mode in DOS, right?
    : : :
    : : Ok, are you saying you want the pixel to move only if press the up arrow key? The code you have above says that while no key has been pressed, the pixel will still move. Only when when you press a key, the pixel doesn't move, but because there is no delay outside of the while loop, you can't see it.
    : :
    :
    : Well, it's the only loop in the program, so it should shut down when I press a key.
    :

    Try this code then :
    repeat
    If not Keypressed then
    begin
    inc(x);
    putpixel(getmaxy div 2, x,white);
    end else Done := true;
    delay(50);
    until Done;
  • Thanks a lot for your help, but I finally found a way to make it work. I tried to use wincrt instead of crt, and it worked! Though, i can't use clrscr now, but I don't really need it...
Sign In or Register to comment.

Howdy, Stranger!

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

Categories