Results 1 to 7 of 7

Thread: Mouse Units for FPC

  1. #1

    Mouse Units for FPC

    System: Windows XP
    Compiler/IDE: Pure, Non-Lazarus Free Pascal
    API: ANY!!!

    OK, I need a good, easy to use, WELL DOCUMENTED mouse unit. I've been searching for the past 2 hours, and have found nothing that works in Pascal. The mouse unit that comes shipped with pascal won't work properly, (I made a simple app to show the x,y coordinates... worked fine, was in a repeat until block, checks to see if you clicked a certain pixel that had a '@' sign on it... if you click ANYWHERE, it would make the x,y coordinates stop updating... And it was not at all accurate.) and every mouse unit I've found either is for TP7 and uses TPU files (of which I can't use in FPC ) or else just sucks.

    HELP!!

    Oh, and thanks for the help when I get it
    --MagicRPG--

  2. #2

    Mouse Units for FPC

    Text mode? Graphics? What graphics API?

  3. #3

    Mouse Units for FPC

    Text-Mode, no graphics.
    --MagicRPG--

  4. #4

    Mouse Units for FPC

    Okay, so I assume that you're looking for a textmode Windows console mouse unit under FPC.

    The best solution is to use a native fpc unit, I don't know why it doesn't work for you, but you may find the answer at FPC community site. Unit's reference with examples is here.

    If it still doesn't work, try this code:
    [pascal]unit MouseUnit;

    interface

    Procedure ShowCursor; Assembler;
    Procedure HideCursor; Assembler;

    Procedure GetStatus(Var X, Y, ButtonStatus :Integer);
    { usage:
    var x, y, button : integer;

    GetStatus(x, y, button);

    This procedure will return mouse position in x,y and
    with button is pressed (0 - left, 1 - middle, 2 - right)
    }

    Procedure DefineHRange(Min, Max :Integer); Assembler;
    Procedure DefineVRange(Min, Max :Integer); Assembler;
    Procedure MouseRange(X1, Y1, X2, Y2 :Integer);
    Function MouseIn(X1, Y1, X2, Y2 :Integer) :Boolean; // checks if mouse is in given area
    Procedure SetSensivity(Hor, Ver :Integer); Assembler;
    Procedure GetSensivity(Var Hor, Ver :Integer);
    Procedure SetPosition(X, Y :Integer); Assembler;

    implementation

    Procedure ShowCursor; Assembler;
    Asm
    mov ax, 0001h
    int 33h
    End;

    Procedure HideCursor; Assembler;
    Asm
    mov ax, 0002h
    int 33h
    End;

    Procedure GetStatus(Var X, Y, ButtonStatus :Integer);
    Var Temp1, Temp2, Temp3 :Word;
    Begin
    Asm
    mov ax, 0003h
    int 33h
    mov Temp1, bx
    mov Temp2, cx
    mov Temp3, dx
    End;
    ButtonStatus := Temp1;
    X := Temp2;
    Y := Temp3;
    End;

    Procedure DefineHRange(Min, Max :Integer); Assembler;
    Asm
    mov ax, 0007h
    mov cx, Min
    mov dx, Max
    int 33h
    End;

    Procedure DefineVRange(Min, Max :Integer); Assembler;
    Asm
    mov ax, 0008h
    mov cx, Min
    mov dx, Max
    int 33h;
    End;

    Procedure MouseRange(X1, Y1, X2, Y2 :Integer);
    Begin
    DefineHRange(X1,X2);
    DefineVRange(Y1,Y2);
    End;

    Function MouseIn(X1, Y1, X2, Y2 :Integer) :Boolean;
    Var
    MouseStatus, PosX, PosY :Integer;
    Begin
    GetStatus(PosX,PosY,MouseStatus);
    If (PosX >= X1) And (PosX <X2>= Y1) And (PosY <= Y2) Then MouseIn := True Else MouseIn := False;
    End;

    Procedure SetSensivity(Hor, Ver :Integer); Assembler;
    Asm
    mov ax, 001Ah
    mov bx, Hor
    mov cx, Ver
    mov dx, 0
    int 33h
    End;

    Procedure GetSensivity(Var Hor, Ver :Integer);
    Var Temp1, Temp2 :Word;
    Begin
    Asm
    mov ax, 001Bh
    int 33h
    mov Temp1, bx
    mov Temp2, cx
    End;
    Hor := Temp1;
    Ver := Temp2;
    End;

    Procedure SetPosition(X, Y :Integer); Assembler;
    Asm
    mov ax, 0004h
    mov cx, x
    mov dx, y
    int 33h
    End;

    end.
    [/pascal]

    To make it workable you'll have to switch from AT&T to Intel style assembler via options/compiler/assembler (if it's pure FPC). Haven't used it for ages, but maybe it'll help you.

  5. #5

    Mouse Units for FPC

    Well, the thing is, I've gone through that code over and over again (the stuff off the FPC site) and I've made a working copy... But the mouse is horribly inaccurate, and when I click ANYWHERE, it doesn't work. And then, theres very little documentation on using the FPC mouse unit... I have no clue how to use 3/4 of the things on there. I don't know how to properly read input, don't know what 'queues' are when referring to the mouse (IE, I don't know how they are used, why, or whether they are necessary), and I absolutely cannot find any documentation online...
    --MagicRPG--

  6. #6

    Mouse Units for FPC

    Dunno if it'll help you, but here's a link to some stuff: http://www.programmersheaven.com/zon...t580/index.htm

  7. #7

    Mouse Units for FPC

    Well, I found the answer in the most unlikely place... In the hidemouse; function's example. It showed me proper usage of GetMouseEvent, which is exactly what I needed

    @Bijo: Yeah, I'd checked that a few times... Wasn't of use though.
    --MagicRPG--

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •