: : : : : : : :
This message was edited by Phat Nat at 2006-12-12 17:31:50
: : : : : : : : : 1. How do I use the mouse in pascal? Im trying to have a program react to the left and right mouse click...
: : : : : : : : :
: : : : : : : : : 2. Furthermore I am trying to store the information I collect in the way in a txt file. Ive programmed pascal to store keys the program user enters in a .dat file but i expect that this process will have no way of storing which mouse button is clicked just like it cannot store the left or right key stroke but uses an empty space to do this... Is there any way around this?
: : : : : : : : :
: : : : : : : :
: : : : : : : : For storing the Left & Right keystrokes you need to read READKEY twice. The first time will return a "0" (meaning extended function) and the second key will be the real keystroke value (75=Left 77=Right)
: : : : : : : : If these values are found, you could store them as characters 27 & 26 (<Left Arrow> & <Right Arrow>) for easier deciphering.
: : : : : : : :
: : : : : : : : As for the Mouse, if you're using TP7 this will work (as it supports inline assembly). It's not in a unit, but it will get the job done. It will give you the X, Y & Buttons of the mouse.
: : : : : : : : Mouse Buttons: Lf=1, Rt=2, Lf&Rt=3, Cn=4, Lf&Cn=5, etc
: : : : : : : :
: : : : : : : :
: : : : : : : : PROCEDURE GetMouse(VAR MouseX, MouseY : Word; VAR MouseB : Byte); Assembler;
: : : : : : : : ASM
: : : : : : : : Mov Ax, $0003 { Function 3 = Get Mouse X,Y & Buttons }
: : : : : : : : Int $33 { Int $33 = Mouse Functions }
: : : : : : : : Shr Cx, 1 { Divide MouseX by 2 }
: : : : : : : : Les Di, MouseX { ES:DI = @MouseX }
: : : : : : : : Mov Es:[Di], Cx { MouseX is returned as 0-639, I want 0-319 }
: : : : : : : : Les Di, MouseY { ES:DI = @MouseY }
: : : : : : : : Mov Es:[Di], Dx { MouseY is returned as 0-199 }
: : : : : : : : Les Di, MouseB { ES:DI = @MouseB }
: : : : : : : : Mov Es:[Di], Bl { Mouse Buttons }
: : : : : : : : End;
: : : : : : : :
: : : : : : : :
: : : : : : : : Hope this is what you need.
: : : : : : : : Phat Nat
: : : : : : : :
: : : : : : : : PS - Thought you may want these too:
: : : : : : : :
: : : : : : : : PROCEDURE ShowMouse; Assembler;
: : : : : : : : ASM
: : : : : : : : Mov Ax, $0001 { Function 1 = Show Mouse Cursor }
: : : : : : : : Int $33 { Int $33 = Mouse Functions }
: : : : : : : : End;
: : : : : : : :
: : : : : : : : PROCEDURE HideMouse; Assembler;
: : : : : : : : ASM
: : : : : : : : Mov Ax, $0000 { Function 0 = Hide Mouse Cursor }
: : : : : : : : Int $33 { Int $33 = Mouse Functions }
: : : : : : : : End;
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : :
: : : : : : :
: : : : : : : Hi PhatNat,
: : : : : : : thanks for your reply, as always. One question, Im trying to use this procedure in a pascal program:
: : : : : : :
: : : : : : : PROGRAM Mouze;
: : : : : : : USES Crt;
: : : : : : :
: : : : : : :
: : : : : : : PROCEDURE GetMouse(VAR MouseX, MouseY : Word; VAR MouseB : Byte); Assembler;
: : : : : : : ASM
: : : : : : : Mov Ax, $0003 { Function 3 = Get Mouse X,Y & Buttons }
: : : : : : : Int $33 { Int $33 = Mouse Functions }
: : : : : : : Shr Cx, 1 { Divide MouseX by 2 }
: : : : : : : Les Di, MouseX { ES:DI = @MouseX }
: : : : : : : Mov Es:[Di], Cx { MouseX is returned as 0-639, I want 0-319 }
: : : : : : : Les Di, MouseY { ES:DI = @MouseY }
: : : : : : : Mov Es:[Di], Dx { MouseY is returned as 0-199 }
: : : : : : : Les Di, MouseB { ES:DI = @MouseB }
: : : : : : : Mov Es:[Di], Bl { Mouse Buttons }
: : : : : : : End;
: : : : : : :
: : : : : : : BEGIN
: : : : : : : GetMouse;
: : : : : : : END.
: : : : : : :
: : : : : : : When I try to compile this i get "Error 88:"(" Expected. Fro the bit of research i did i gather that not every procedure needs to be followed by a bracket... What should I put in the brackets?
: : : : : : :
: : : : : : : thx!
: : : : : : : NA
: : : : : : :
: : : : : : The variables to receive the location of the mouse cursor and buttons, i.e.:
: : : : : :
: : : : : : VAR MouseX, MouseY : Word; VAR MouseB : Byte
: : : : : :
: : : : : : as seen in the declaration of the procedure.
: : : : : :
: : : : : :
: : : : :
: : : : :
: : : : : But I still have no way of knowing what MouseX and MouseY etc are? Simply entering these variables does not get me anywhere. What should I do to avoid this error "Error 88"?
: : : : :
: : : : : thx so much!
: : : : : NA
: : : : :
: : : : You don't need to enter the variables. These variables are set by the procedure GetMouse(), and hold the location of the mouse. If you want to do something using the mouse position, you can read those variables.
: : : : This example shows the mouse coordinates on the screen:
: : : :
: : : : begin
: : : : repeat
: : : : GetMouse(MouseX, MouseY, MouseB); { Sets the variables }
: : : : GotoXY(1, 1);
: : : : writeln(MouseX, MouseY); { Uses the location }
: : : : until MouseB > 0; { Checks if the user clicks to end the program }
: : : : end;
: : : :
: : : :
: : : :
: : :
: : : and what type should these variables be? I tried string and integer, both didnt work...:(
: : :
: : :
: : As you can see from this code:
: :
: : PROCEDURE GetMouse(VAR MouseX, MouseY : Word; VAR MouseB : Byte);
: :
: : they must be
word and
byte. Var parameters
must be precisely the same as specified in the procedure declaration.
: :
:
: "MouseB" only recognized whether or not a mouse button has been pressed. What code will tell me whether someone pushed the LEFT mouse button or the RIGHT one?
:
:
Probably by the number returned in the MouseB. Just test it, by showing the results of MouseB on the screen.