How to use the mouse for input in a console application?

atth
atth used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi Atth,

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)

Commented:
... plus the TTimer object can be used to provide the delay you want.

Author

Commented:
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.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

add this:

uses Windows;

and to add the delay:

sleep(100); // delay for 100 ms

Commented:
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.  

Author

Commented:
thanks DragonSlayer.. the sleep() thingie works.. any ideas for mouse input?

Author

Commented:
swift99.. i'm totally blur.. still i appreciate the help..

Commented:
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.

Author

Commented:
hmm.. i found some mouse libraries at http://www.simtel.net/pub/msdos/turbopas/ .. not sure how to use(compile etc.) them..

Commented:
I'll have to look at that tonight.  Pascal is Pascal, so it should be pretty straightforward.
awaiting swift99's answer ;)

Commented:
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,count,mouse_clicked_x,mouse_clicked_y);
    if count > 0 then HandleMouseClick

    // handle events
end;  

Commented:
HandleMouseClick is you procedure for setting up cells.

Commented:
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.

Author

Commented:
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?

Commented:
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).

Author

Commented:
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!
Commented:
no prob.

mouse programming in the dos world was considered arcane.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial