Using the Mouse in Pascal - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Using the Mouse in Pascal

NinthAngleNinthAngle Posts: 98Member
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?
«1

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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?
    :
    In TP6+, you can use the Mouse unit. This unit defines the TMouse object, which can be used to gain access to the mouse routines. The mouse unit also defines several constants which are returned in response to the various button clicks. You can store those constants in a text file.
  • NinthAngleNinthAngle Posts: 98Member
    : : 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?
    : :
    : In TP6+, you can use the Mouse unit. This unit defines the TMouse object, which can be used to gain access to the mouse routines. The mouse unit also defines several constants which are returned in response to the various button clicks. You can store those constants in a text file.
    :

    I have TP7 and I just looked up "mouse" in the index, but for some strange reason my index is now in french??? even though all the other menus in tp are english. Is there any way for me to fix this?

    Is ther eanother place I can learn more about how to use the mouse in tp beside this forum and the index?
  • AlcatizAlcatiz Posts: 51Member
    : : : 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?
    : : :
    : : In TP6+, you can use the Mouse unit. This unit defines the TMouse object, which can be used to gain access to the mouse routines. The mouse unit also defines several constants which are returned in response to the various button clicks. You can store those constants in a text file.
    : :
    :
    : I have TP7 and I just looked up "mouse" in the index, but for some strange reason my index is now in french??? even though all the other menus in tp are english. Is there any way for me to fix this?
    :
    : Is ther eanother place I can learn more about how to use the mouse in tp beside this forum and the index?
    :
    Hi !

    The only version of Turbo Pascal 7 released by Borland to public domain is the French one. In a legal way you can find the TP 5.5 English help files.
  • Phat NatPhat Nat Posts: 757Member
    [b][red]This message was edited by Phat Nat at 2006-12-12 17:31:50[/red][/b][hr]
    : 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 ( & ) 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

    [code]
    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;
    [/code]

    Hope this is what you need.
    Phat Nat

    PS - Thought you may want these too:
    [code]
    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;
    [/code]





  • NinthAngleNinthAngle Posts: 98Member
    : [b][red]This message was edited by Phat Nat at 2006-12-12 17:31:50[/red][/b][hr]
    : : 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 ( & ) 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
    :
    : [code]
    : 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;
    : [/code]
    :
    : Hope this is what you need.
    : Phat Nat
    :
    : PS - Thought you may want these too:
    : [code]
    : 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;
    : [/code]
    :
    :
    :
    :
    :
    :


    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
  • zibadianzibadian Posts: 6,349Member
    : : [b][red]This message was edited by Phat Nat at 2006-12-12 17:31:50[/red][/b][hr]
    : : : 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 ( & ) 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
    : :
    : : [code]
    : : 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;
    : : [/code]
    : :
    : : Hope this is what you need.
    : : Phat Nat
    : :
    : : PS - Thought you may want these too:
    : : [code]
    : : 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;
    : : [/code]
    : :
    : :
    : :
    : :
    : :
    : :
    :
    :
    : 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.:
    [code]
    VAR MouseX, MouseY : Word; VAR MouseB : Byte
    [/code]
    as seen in the declaration of the procedure.

  • NinthAngleNinthAngle Posts: 98Member
    : : : [b][red]This message was edited by Phat Nat at 2006-12-12 17:31:50[/red][/b][hr]
    : : : : 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 ( & ) 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
    : : :
    : : : [code]
    : : : 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;
    : : : [/code]
    : : :
    : : : Hope this is what you need.
    : : : Phat Nat
    : : :
    : : : PS - Thought you may want these too:
    : : : [code]
    : : : 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;
    : : : [/code]
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : :
    : :
    : : 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.:
    : [code]
    : VAR MouseX, MouseY : Word; VAR MouseB : Byte
    : [/code]
    : 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
  • zibadianzibadian Posts: 6,349Member
    : : : : [b][red]This message was edited by Phat Nat at 2006-12-12 17:31:50[/red][/b][hr]
    : : : : : 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 ( & ) 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
    : : : :
    : : : : [code]
    : : : : 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;
    : : : : [/code]
    : : : :
    : : : : Hope this is what you need.
    : : : : Phat Nat
    : : : :
    : : : : PS - Thought you may want these too:
    : : : : [code]
    : : : : 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;
    : : : : [/code]
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : :
    : : :
    : : : 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.:
    : : [code]
    : : VAR MouseX, MouseY : Word; VAR MouseB : Byte
    : : [/code]
    : : 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:
    [code]
    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;
    [/code]

  • NinthAngleNinthAngle Posts: 98Member
    : : : : : [b][red]This message was edited by Phat Nat at 2006-12-12 17:31:50[/red][/b][hr]
    : : : : : : 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 ( & ) 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
    : : : : :
    : : : : : [code]
    : : : : : 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;
    : : : : : [/code]
    : : : : :
    : : : : : Hope this is what you need.
    : : : : : Phat Nat
    : : : : :
    : : : : : PS - Thought you may want these too:
    : : : : : [code]
    : : : : : 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;
    : : : : : [/code]
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : :
    : : : :
    : : : : 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.:
    : : : [code]
    : : : VAR MouseX, MouseY : Word; VAR MouseB : Byte
    : : : [/code]
    : : : 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:
    : [code]
    : 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;
    : [/code]
    :
    :

    and what type should these variables be? I tried string and integer, both didnt work...:(

  • zibadianzibadian Posts: 6,349Member
    : : : : : : [b][red]This message was edited by Phat Nat at 2006-12-12 17:31:50[/red][/b][hr]
    : : : : : : : 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 ( & ) 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
    : : : : : :
    : : : : : : [code]
    : : : : : : 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;
    : : : : : : [/code]
    : : : : : :
    : : : : : : Hope this is what you need.
    : : : : : : Phat Nat
    : : : : : :
    : : : : : : PS - Thought you may want these too:
    : : : : : : [code]
    : : : : : : 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;
    : : : : : : [/code]
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : :
    : : : : :
    : : : : : 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.:
    : : : : [code]
    : : : : VAR MouseX, MouseY : Word; VAR MouseB : Byte
    : : : : [/code]
    : : : : 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:
    : : [code]
    : : 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;
    : : [/code]
    : :
    : :
    :
    : and what type should these variables be? I tried string and integer, both didnt work...:(
    :
    :
    As you can see from this code:
    [code]
    PROCEDURE GetMouse(VAR MouseX, MouseY : [red]Word[/red]; VAR MouseB : [red]Byte[/red]);
    [/code]
    they must be [b]word[/b] and [b]byte[/b]. Var parameters [b][size=4]must be precisely the same[/size][/b] as specified in the procedure declaration.
«1
Sign In or Register to comment.