PDA

View Full Version : Limiting mouse movement to specific range



atozix
18-10-2003, 08:59 PM
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

Paulius
19-10-2003, 08:04 AM
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.

atozix
19-10-2003, 11:09 AM
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

Harry Hunt
19-10-2003, 05:33 PM
What about ClipCursor ?

atozix
20-10-2003, 11:49 PM
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

Alimonster
21-10-2003, 08:48 AM
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.

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

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

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

atozix
21-10-2003, 11:23 AM
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.

atozix
21-10-2003, 07:58 PM
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

Alimonster
22-10-2003, 11:54 AM
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? :P

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 (http://terraqueous.f2o.org/dgdev/profile.php?mode=viewprofile&u=2) to take over the world, muhaha!).

atozix
22-10-2003, 07:14 PM
(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

atozix
24-10-2003, 07:55 PM
Another thought re

GetCursorPos / SetCursorPos versus ClipCursor

If ones program does not error check properly and the program crashes !@#$%^&*() with ClipCursor the user could be stuck with limited cursor movement , whereas this would not occur with the get/set method..

cheeeeeeerrrrrrrrrsssssssss ato

doggo18
25-10-2003, 12:21 AM
But ClipCursor is less CPU intensive, as to checking before setting instead of correcting ;)