Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Limiting mouse movement to specific range

  1. #1

    Limiting mouse movement to specific range

    Hi ho ,,

    I want to limit the mouse movements within a fullscreen app using DelphiX and Delphi 5 so that for example , it can only appear and move within a specified area of the screen... whether using the default mouse pointer or a user defined mouse image..

    Also it would be handy to be able to do this in a windowed app...

    There must be some simple method to achieving this, but it eludes me...

    HOW ? HELP

    cheeeeeeeeeeerrrrrrrrsssssssssssss atozix
    The Universe is all right here!!!

  2. #2

    Limiting mouse movement to specific range

    How about using GetCursorPos, checking if it?¢_~s out of bounds and if it is using SetCursorPos to put the cursor where you want it.

  3. #3

    Limiting mouse movement to specific range

    Hi Paulius,,,

    Aha another fellow timewaster ....

    EXCELLENT GetCursorPos and SetCursorPos do exactly what I want...
    As when you exceed the bounds with a mouse movement, upon moving into the direction of the bounds the cursor responds instantly....

    THX........ and may u waste time friutfully?? frightfully aha i have it Fruitfully heheheh

    cheeeeeeeerrrrrrssssssss atozix
    The Universe is all right here!!!

  4. #4

    Limiting mouse movement to specific range

    What about ClipCursor ?
    Ask me about the xcess game development kit

  5. #5

    Limiting mouse movement to specific range

    Hi Harry,,

    As mentioned above the
    GetCursorPos and SetCursorPos works well...

    But different methods have their uses, so I tried to check out
    ClipCursor... with no success lacking documentation in help file...

    So, EXACTLY , how would you use it??

    cheeeeeeeeeeeerrrrrsssss aaand thx for reply a
    The Universe is all right here!!!

  6. #6

    Limiting mouse movement to specific range

    Quote Originally Posted by atozix
    Hi Harry,,

    As mentioned above the
    GetCursorPos and SetCursorPos works well...

    But different methods have their uses, so I tried to check out
    ClipCursor... with no success lacking documentation in help file...

    So, EXACTLY , how would you use it??

    cheeeeeeeeeeeerrrrrsssss aaand thx for reply a
    The documentation for this is in the win32.hlp file. The simplest method to get to it is to type "ClipCursor" into the code editor, put the caret inside the word, then hit F1. Maybe Delphi 7 removed win32.hlp, dunno (though that would be surprising).

    Anyway, you pass in a pointer-to-TRect to set the mouse bounds and pass in nil to remove the clip rectangle when you've finished. E.g.

    [pascal]var
    MyRect: TRect;
    begin
    MyRect := Bounds(10, 10, 32, 32);
    ClipCursor(@MyRect);

    // blah blah blah, we're finished now
    ClipCursor(nil);
    end;[/pascal]

    Here's the description for ClipCursor (note it contains C++-isms like "NULL" instead of "nil" and RECT instead of TRect):

    The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, Windows automatically adjusts the position to keep the cursor inside the rectangular area.

    BOOL ClipCursor(
    CONST RECT *lpRect // pointer to structure with rectangle
    );

    Parameters

    lprc

    Points to the RECT structure that contains the screen coordinates of the upper-left and lower-right corners of the confining rectangle. If this parameter is NULL, the cursor is free to move anywhere on the screen.


    Return Values

    If the function succeeds, the return value is nonzero.
    If the function fails, the return value is zero. To get extended error information, call GetLastError.

    Remarks

    The cursor is a shared resource. If an application confines the cursor, it must release the cursor by using ClipCursor before relinquishing control to another application.
    The calling process must have WINSTA_WRITEATTRIBUTES access to the window station.

    See Also

    GetClipCursor, GetCursorPos, RECT, SetCursorPos
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  7. #7

    Limiting mouse movement to specific range

    Hi Alimonster,,,

    Thx, I'll check it out..

    and by the way, I love the quote.... hehehe

    "All paid jobs absorb and degrade the mind."
    -- Aristotle

    cheeeeeeeerrrrrssssss a

    also i will post another beginner question before logging off.
    The Universe is all right here!!!

  8. #8

    Limiting mouse movement to specific range

    Hi ho Alimonster,,

    Hmmm .. This method is even easier , but one has to remember to
    ClipCursor(nil); before exiting the program as the cursor stays clipped,
    being w32 i spose... So I just put the ClipCursor(nil); in FormClose..


    in regard to the help docs,,,, your method of finding the info from within the editor also works fine.... but if i just do a search nowt is revealed...

    probly cause my delphi help will not complete a create list ...
    when I try to create a list by clicking on FIND I get the error message

    unable to display find tab[177] (windows help message)

    hmmm this used to work last time i was programming a few years ago!!!

    so ive just been using the index ...


    anyway THX again for the clip method....

    cheeeeeeeeeerrrrrrrssssssss a
    The Universe is all right here!!!

  9. #9

    Limiting mouse movement to specific range

    Quote Originally Posted by atozix
    Hi ho Alimonster,,

    Hmmm .. This method is even easier , but one has to remember to
    ClipCursor(nil); before exiting the program as the cursor stays clipped,
    being w32 i spose... So I just put the ClipCursor(nil); in FormClose..
    Yeah, there are a few more to remember too. For example, switching away from the application (OnActivate/OnDeactivate for the TApplication object), minimization and restoration, and so on. Though I can't remember if those require specific handling or if Windows deals with it. If you need to handle those then try dropping down a TApplicationEvents component from the Additional tab. Bear in mind that I've not used DelphiX, so I don't know how that will affect things.

    in regard to the help docs,,,, your method of finding the info from within the editor also works fine.... but if i just do a search nowt is revealed...

    probly cause my delphi help will not complete a create list ...
    when I try to create a list by clicking on FIND I get the error message

    unable to display find tab[177] (windows help message)

    hmmm this used to work last time i was programming a few years ago!!!

    so ive just been using the index ...
    Yeah, that's happened to me before -- in fact, it's a problem at the moment at work with Delphi 5 Enterprise. I'm not sure of a good fix, to be honest, since I've not looked for one yet. Would a cheap and cheerful fix be any better?

    The win32.hlp help file is separate from the other Delphi ones. The simplest fix is to customize the Delphi toolbar. Right-click on the toolbar icons, choose customize, select the "commands" tab, and drag on the Windows API button from the help category (I choose the top row, just to the right of the normal help button). You can also drag something underneath it to make it look less silly (I choose "close all" from the file category).

    You can try a more direct approach. Have a look in the Help menu and see if there's a "customize" menu. If there's something like that available then you should be able to play around with the various help files. If you manage to fix the problem then let me know cause I'm interested too! :roll:

    anyway THX again for the clip method....

    cheeeeeeeeeerrrrrrrssssssss a
    No problem, we're here to help (as part of a sinister plot to take over the world, muhaha!).
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  10. #10

    Limiting mouse movement to specific range

    (If you manage to fix the problem then let me know cause I'm interested too! :roll: )


    Hi ho Alimonster,,

    Will do...!

    AND you are failing to take into account re sinister plot that the entire world has always been a sinister plot by powers beyond our control YET, so we are just sub plotters....

    hohohoho hahahahahh plop falllls off chair

    cheeeeeeeerrrrrrrrrsssssssssss ato
    The Universe is all right here!!!

Page 1 of 2 12 LastLast

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
  •