Recent

Author Topic: Initgraph and KeyBoard input  (Read 6475 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Initgraph and KeyBoard input
« on: November 21, 2011, 08:37:30 am »
Hello guys, who knows me explain why this code does not work?! I would then take an input from the keyboard but does not work! fill would print the message but does not read keyboard input. Why?

Code: [Select]
Program Prova;
Uses Crt,Graph;
Var Gd,Gm:integer;
    Scelta:char;

Begin
Gd:=detect;
Initgraph(Gd,Gm,'C:\FPC');
Rectangle(0,0,766,1365);
SetfillStyle(1,11);
Floodfill(1,1,11);
Outtextxy(0,40,'Prova!!!');
Outtextxy(0,50,'Questa serve per testare una struttura If...then semplice');
Outtextxy(0,60,'Premi A');
Read(Scelta);
If (Scelta='a') then Outtextxy(0,80,'GIUSTO!') else OuttextXy(0,80,'SBAGLIATO!');
Readkey;
end.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Initgraph and KeyBoard input
« Reply #1 on: November 21, 2011, 04:50:46 pm »
No idea?!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Initgraph and KeyBoard input
« Reply #2 on: November 21, 2011, 05:41:16 pm »
Are you trying to run this on windows? It'll work but not as you intended  ;D It creates a window to display the graphics and then listen for input on the console. Run it from a console and you see what I mean.
To use graph on windows, you need to use winCrt. Here is a modified version that works on windows
Code: [Select]
Program prova;

Uses winCrt,Graph;

Var
    Gd,Gm:smallint;
    Scelta:char;

Begin
Gd:=detect;
Initgraph(Gd,Gm,'C:\FPC');
Rectangle(0,0,100,200);
SetfillStyle(1,11);
//Floodfill(1,1,11);
Outtextxy(0,40,'Prova!!!');
Outtextxy(0,50,'Questa serve per testare una struttura If...then semplice');
Outtextxy(0,60,'Premi A');
Scelta:=readkey;
If (Scelta='a') then Outtextxy(0,80,'GIUSTO!') else OuttextXy(0,80,'SBAGLIATO!');
Readkey;
end.


Don't use read because that is again reading from the console instead of the graphics window.

 

TinyPortal © 2005-2018