atth
asked on
How to use the mouse for input in a console application?
I'm a beginner at programming. I'm trying to write a program that runs Conway's 'Game of Life'. Is it possible to use a mouse to 'enter' the initial configuration in a console application? All that is needed is the X,Y coordinates of where the user has 'clicked'. One more question, is there a timer or delay function that i can use? Currently i'm calling a function that counts from 1 to 100 million or something like that to artificially create time intervals but that's a waste of processing power. Thanks in advance for your help.
... plus the TTimer object can be used to provide the delay you want.
ASKER
sorry i didn't clarify. I need to do this all in command prompt only. no visual components allowed. i have the program up and running already thanks. the problem is with the user interface. it's a bit tedious for the user to input x,y coordinates for the initial configuration. on a 80 x 24 grid (standard command prompt) it would be extremely hard to get any useful pattern. also i need the delay because hitting 'enter' to generate the next generation isn't a very practical solution. hope someone can provide some insight.
add this:
uses Windows;
and to add the delay:
sleep(100); // delay for 100 ms
uses Windows;
and to add the delay:
sleep(100); // delay for 100 ms
About 10 years ago I had code to address the mouse from a console app. :o(
Maybe someone has TP4, 4, or 6 around - its cursor libraries should be transportable to the Delphi compiler.
Maybe someone has TP4, 4, or 6 around - its cursor libraries should be transportable to the Delphi compiler.
ASKER
thanks DragonSlayer.. the sleep() thingie works.. any ideas for mouse input?
ASKER
swift99.. i'm totally blur.. still i appreciate the help..
Turbo pascal (TP) is the precursor to Delphi. The Delphi 6 compiler is, internally, Turbo Pascal version 13, hence the ($IFDEF VER130} directive.
The pre-Delphi libraries should still compile if you can find them.
The pre-Delphi libraries should still compile if you can find them.
ASKER
hmm.. i found some mouse libraries at http://www.simtel.net/pub/msdos/turbopas/ .. not sure how to use(compile etc.) them..
I'll have to look at that tonight. Pascal is Pascal, so it should be pretty straightforward.
awaiting swift99's answer ;)
Sorry ... family first.
Let's take the mouse.pas unit from amouse for example. It's TP 5.5 so it's not object based. It's a straightforward procedureal unit. Pull it out of the zip file and into a directory in your search path (say your project directory if you don't intend to reuse it).
program myprog;
uses mouse;
begin
// while not done
// poll mouse for events
// ... poll mouse
button_pressed(button,coun t,mouse_cl icked_x,mo use_clicke d_y);
if count > 0 then HandleMouseClick
// handle events
end;
Let's take the mouse.pas unit from amouse for example. It's TP 5.5 so it's not object based. It's a straightforward procedureal unit. Pull it out of the zip file and into a directory in your search path (say your project directory if you don't intend to reuse it).
program myprog;
uses mouse;
begin
// while not done
// poll mouse for events
// ... poll mouse
button_pressed(button,coun
if count > 0 then HandleMouseClick
// handle events
end;
HandleMouseClick is you procedure for setting up cells.
The mouse procedures use software interrupt 13. I haven't checked, but if Delphi no longer supports the "intr" pseudo-procedure, then you may code it with inline assembly as ...
asm
int $13
end;
You will have to read the Delphi compiler manual to get the order of population for registers, and then you can use use inline assembly to ensure that you populate the registers from the correct parameter variables.
asm
int $13
end;
You will have to read the Delphi compiler manual to get the order of population for registers, and then you can use use inline assembly to ensure that you populate the registers from the correct parameter variables.
ASKER
the mouse procedure uses dos.. compiler error "dos.dcu" not found.. that's the only error i get so far.. thanks for all the help so far.. any ideas where i can get the dos unit?
My old diskettes all had water damage so they're gone.
I'll see what I can come up with ... I imagine you will need to rewrite one or two functions (like INTR for example).
I'll see what I can come up with ... I imagine you will need to rewrite one or two functions (like INTR for example).
ASKER
swift.. thanks for the help, i think i more or less get what you're getting at.. if it's too much trouble don't bother.. it's not required for my homework, and next term we'll be doing visual components.. thanks for all your help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need an array of timage s to build a graphic grid for the Conway's game of life. Each Timage component has a method OnClick so you can do whatever you want when you click over one element of the grid.
Check first
http://www.delphicorner.f9.co.uk/articles/comps7.htm
to see how to build an array of components.
Tell me if you need more assistance.
Best regards
Manuel Lopez (lopem)