Keeping the mouse pointer within a window

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Keeping the mouse pointer within a window

Post by sefrojones » Fri Mar 14, 2014 5:04 am

I'm trying to keep the mouse cursor inside the boundaries of my stack. I've been messing with the screenMouseLoc property, but I can't see to figure it out. Any tips?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Keeping the mouse pointer within a window

Post by Simon » Fri Mar 14, 2014 5:30 am

Hi sefrojonesGAda40,
Give this a try in the card script

Code: Select all

on mouseMove newMouseH,newMouseV
   if item 1 of the mouseLoc < 10 then
      set the screenMouseLoc to the (Left of this stack + 10), item 2 of the screenMouseLoc
   end if
end mouseMove
That is only for the left you will have to figure out the other 3 sides.
Needed that "10" as a margin as the idle rate can be to slow for a really fast motion.

Mind you a function like this would really ummm upset me.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Keeping the mouse pointer within a window

Post by sefrojones » Fri Mar 14, 2014 7:16 am

Thanks simon, this is only for when my gameloop is running. otherwise if a user clicks outside of the stack it loses focus, or does not operate correctly.

EDIT: this is what i ended up going with for now, it works well. Thanks Simon!

Code: Select all

on mousemove
if the vis of grp "getready" is false then
   if item 1 of the mouseLoc < 60 then
      set the screenMouseLoc to the (Left of this stack + 60), 500
    set the loc of grp "player" to item 1 of the mouseloc,500
   end if
   if item 1 of the mouseLoc > 740 then
      set the screenMouseLoc to the (right of this stack - 60), 500
      set the loc of grp "player" to item 1 of the mouseloc,500
   end if
    if item 2 of the mouseLoc < 500 then
       set the screenMouseLoc to item 1 of the screenmouseloc,500
      set the loc of grp "player" to item 1 of the mouseloc,500
    end if
    
        if item 2 of the mouseLoc > 500 then
           set the screenMouseLoc to the item 1 of the screenMouseLoc,500
        end if
        set the loc of grp "player" to item 1 of the mouseloc,500
end if
end mousemove

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Keeping the mouse pointer within a window

Post by jacque » Fri Mar 14, 2014 5:50 pm

Please don't restrict the user's cursor. Really. Don't do it. It goes against every interface prohibition. Unless the user knows how to switch apps with the keyboard shortcuts (and many do not) you have restricted them to your app without any way to get out. Some novices may actually restart their machine in order to quit, and they will be convinced your app is too buggy to use.

You can't assume that people know how to navigate without a mouse. I know a Windows user who has been using his computer for years and didn't know about the keyboard shortcuts for copy/paste, he always used the mouse. Even those who do know how to switch apps will resent yours for taking away control.

It is the app's responbility to manage itself when it goes into the background. See the suspendstack message in the dictionary, it tells you when your app loses focus so that you can take any required actions. Resumestack triggers when the app receives focus again, so that it can do whatever is required to resume the game. If you need help with that, we're here.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Keeping the mouse pointer within a window

Post by sefrojones » Fri Mar 14, 2014 7:17 pm

The user is able to show the cursor/ end the game with the escape key. Since this is an action game, and the cursor will be hidden during gameplay, I don't really think it's a big deal. Is it?

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm

Re: Keeping the mouse pointer within a window

Post by paul_gr » Fri Mar 14, 2014 7:56 pm

sefrojonesGAda40 wrote:The user is able to show the cursor/ end the game with the escape key. Since this is an action game, and the cursor will be hidden during gameplay, I don't really think it's a big deal. Is it?
Maybe 10 years ago it was OK -- before the mouse got popular and computers were not used by everyone. Use of the mouse is so ingrained into the average users habits they tend to panic if their mouse doesn't move when they want it to.
They also do not know what the escape key was designed for.
Most apps these days will not exit with the escape key so users probably have no experience with it.
The mouse rules them all...

Paul

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Keeping the mouse pointer within a window

Post by sefrojones » Fri Mar 14, 2014 9:21 pm

Thanks for the input guys, I think the way to go is with the suspendstack, and resumestack, and just pause the stack when it loses focus.
I will reply when I've got it worked out.

Post Reply