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.

Well, how about using mouse? :)

Fenix61Fenix61 Posts: 9Member
Never knew how to..

any one would create me a simple example?


Comments

  • JaywalkJaywalk Posts: 105Member
    : Never knew how to..
    :
    : any one would create me a simple example?
    :
    The best way is (as always) in assembly. Sorry to those who don't know it, but you can always just copy what I write.



    Procedure ShowMouse; Assembler;
    {This procedure makes a mouse cursor appear. This should do for
    most purposes, but sometimes it is better to just draw the
    cursor manually after reading its coords from MouseX and MouseY}
    Asm
    mov ax,1
    int 33h
    end;

    Procedure HideMouse; Assembler;
    {Hides the mouse cursor. If you call HideMouse more than once
    then you will need to call ShowMouse more than once to make the
    mouse appear again. Best to make sure that you don't call
    HideMouse when the mouse is not visible}
    Asm
    mov ax,2
    int 33h
    end;

    Function MouseL: boolean; assembler;
    {This function returns TRUE if the left mouse button is down}
    Asm
    mov ax,3
    int 33h
    mov al,bh
    and al,1
    end;

    Function MouseR: boolean; assembler;
    {This function returns TRUE if the right mouse button is down}
    Asm
    mov ax,3
    int 33h
    mov al,bl
    and al,2
    end;

    Function MouseX: word; assembler;
    {Returns the X coordinate of the mouse. Depending on the screen mode, you may need to divide the result by some number. For example, in a text mode you need to divide by 8}
    Asm
    mov ax,3
    int 33h
    mov ax,cx
    end;

    Function MouseY: word; assembler;
    {Same as MouseX, except that it returns the Y coordinate}
    Asm
    mov ax,3
    int 33h
    mov ax,dx
    end;



    This is all done from the top of my head, so I don't guaruntee that it's perfect, but hopefully you can just copy it into your code and it will work.

  • Fenix61Fenix61 Posts: 9Member
    Well, there are no errors in your program here, but it doesn't work.

    Just add this to what you write under this and you'll notice that MouseX and MouseY equals 0.
    ---------------------------------------------------
    {...}
    {Up of begin you have your fonctions and procedures}
    {...}
    Begin
    Write(MouseX);
    Write(MouseY);
    Readln;
    End.
    ---------------------------------------------------

    By the way I also tested the MouseL and MouseR by doing this

    If MouseL then halt(0);
    If MouseR then halt(0);

    Didn't work.

    Is it because I have an optical mouse with an adaptator with it? Or is it the wrong interrupt?

    Why don't you send me the code of a program (simple) with a mouse in it that works? I would know if it is my comp or compilator that bugs or your code.

  • ManningManning Posts: 1,621Member
    : This is all done from the top of my head, so I don't guaruntee that it's perfect, but hopefully you can just copy it into your code and it will work.

    The only problem I found was in MouseL. It said:

    mov al,bh

    I changed it to:

    mov al,bl

    And it worked perfect (I admit I dont have the foggiest what the difference is since I dont know ASM...I just seen that MouseR used bl instead of bh and hoped it would work )

    And to reply to the other guys request for an example program, try this: (IntToStr and BoolToStr should be self explanatory and easy for you to write your own version of...FastWrite is just some ASM code I picked out of swag a long time ago. So either go find it there, or replace it with calls to gotoxy and writeln)

    [code]
    begin
    ShowMouse;
    repeat
    fastwrite('X: ' + IntToStr(MouseX div 8 + 1) + ' Y: ' + IntToStr(MouseY div 8 + 1) + ' LButton: ' +
    BoolToStr(MouseL, 'Down', 'Up') + ' RButton: ' + BoolToStr(MouseR, 'Down', 'Up') + ' ', 1, 1, 7);
    until keypressed;
    HideMouse;
    end.
    [/code]

  • chobochobo Posts: 30Member
    tried to use it with the the egavga bgi driver, and it worked fine, but then i wanted to use it with bgi driver by knight software called "bgi256" and it didn't work. i checked it and found out that the mouse's x and y coordinate did change the same way they do in dos/text mode. i had to draw the mouse manually to make it visible.
    how is it possible to set the resolution for the mouse, so that i can use it with other bgi drivers too?

  • JaywalkJaywalk Posts: 105Member
    : tried to use it with the the egavga bgi driver, and it worked fine, but then i wanted to use it with bgi driver by knight software called "bgi256" and it didn't work. i checked it and found out that the mouse's x and y coordinate did change the same way they do in dos/text mode. i had to draw the mouse manually to make it visible.
    : how is it possible to set the resolution for the mouse, so that i can use it with other bgi drivers too?
    :
    It should work every time. Then again, I don't know about whether it works with SVGA graphics. bgi256 may use SVGA - I don't know. Anyway, I personally think that drawing the mouse manually is the best method.

  • chobochobo Posts: 30Member
    ...but drawing the cursor manually isn't a very good solution, since in text mode there r only very few y values for the cursor position (about 25 i think}. 25 positions for a y-resolution of 480... doesn't last, i think.

    any solutions?

Sign In or Register to comment.