LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
palanolho
- Posts: 122
- Joined: Sat Apr 27, 2013 11:40 pm
Post
by palanolho » Tue Apr 30, 2013 11:08 pm
Greetings everyone.
I'm trying to play with my mouse cursor on an application i'm doing but ... i'm having some trouble.
I have a group that i want to change the mouse cursor when the mouse pointer in over the group (anywhere).
so... i tried to use "mouseEnter" and "mouseOut" but with no success. Then I have noticed something in the dictionary that says something about "Browser tool". Does anyone can explain me what this is?
Anyway, I also tried the "mouseWithin" but also, with no success.
Can anyone give me any tip around this? am I doing anything wrong?
Here's the simple script i have used
Code: Select all
on mouseWithin
set the cursor to hand
end mouseWithin
Many thanks in advance
-
sturgis
- Livecode Opensource Backer

- Posts: 1685
- Joined: Sat Feb 28, 2009 11:49 pm
Post
by sturgis » Tue Apr 30, 2013 11:16 pm
Look at mouseEnter and mouseLeave
Also be aware that groups behave strangely with many messages. If you have 3 buttons in your group and move the mouse into the group but don't point at a control, there is no mouseEnter. Once you touch a control the mouseEnter message is sent.
One way around this is to put a graphic into the group as its background and size it so that it fills the group.
Then when you enter the group with the mouse there is always a control there.
Then, if you put the following code into the group:
Code: Select all
on mouseEnter
set the cursor to watch
lock cursor
end mouseEnter
on mouseLeave
unlock cursor
end mouseLeave
When you enter the group the cursor will turn into a watch, when you leave the group it will revert.
-
palanolho
- Posts: 122
- Joined: Sat Apr 27, 2013 11:40 pm
Post
by palanolho » Wed May 01, 2013 12:12 am
It worked, like a char

thank you.
Just one more thing. I have added a little more customization in order to change the cursor only while i'm pressing the CTRL key.
Code: Select all
on mouseEnter
if the controlKey is down then
set the cursor to hand
lock cursor
end if
end mouseEnter
on mouseLeave
unlock cursor
end mouseLeave
The script will work fine when the cursor is out of the group and moves in. However, if the cursor is already over the group when i press it, or it's still over it when i release the CTRL key, the cursor does not change (to the hand or to the original shape).
I tried to use the "on controlKeyDown" and "on controlKeyUp" to try to deal with this but i was not able to. I noticed that this handler will only work on MAC, however i'm developing in windows but also want that this app work on MAC.
Any suggestion ?
Many thanks
-
sturgis
- Livecode Opensource Backer

- Posts: 1685
- Joined: Sat Feb 28, 2009 11:49 pm
Post
by sturgis » Wed May 01, 2013 1:59 am
Need to go about it a little different to accomplish your goal. The following code is commented.
Code: Select all
--declare a script local variable that tracks if the cursor is within the group bounds
local sWithin
-- when the mouse enters the bounds, set the variable to true and call the checkKey function
on mouseEnter
put true into sWithin
checkKey
end mouseEnter
-- when the mouse leaves the group, put false into the variable
on mouseLeave
put false into sWithin
end mouseLeave
-- the grunt work is done here.
command checkKey
-- first check our variable to see if we're in the group
if sWithin then
-- then if we're in the group, see if the control key is down
if the controlkey is down then
-- if the control key is down then set and lock the cursor
set the cursor to watch
lock cursor
else
-- if the control key is NOT down but we're still in the group, unlock the cursor
unlock cursor
end if
-- here the handler calls itself so that it can continue polling the control key
send checkKey to me in 2 ticks
else
-- if we're NOT still within the group, unlock the cursor and don't have the handler call itself.
unlock cursor
end if
end checkKey
EDIT: Here is a link to a working example.
https://dl.dropboxusercontent.com/u/119 ... t.livecode
EDIT2: Fixed a comment
Last edited by
sturgis on Wed May 01, 2013 2:58 am, edited 1 time in total.
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Wed May 01, 2013 2:05 am
Hi palanolho,
I'm going to get in trouble for this because while it will do what you want it could result in very poor performance later on in your code:
Code: Select all
on mouseEnter
if the controlKey is down then
set the cursor to hand
lock cursor
else
unlock cursor
end if
send mouseEnter to me in 10 millisecs --mouseEnter is only triggered once "on Entry"... this repeats it
end mouseEnter
on mouseLeave
unlock cursor
cancelThisMsg(mouseEnter)
end mouseLeave
on cancelThisMsg tMsg --As you leave there are still mouseEnter messages being sent-- this cancels them
put the pendingmessages into tPendingMsgs
if tMsg is in tPendingMsgs then
repeat FOR each line x in tPendingMsgs
if tMsg is in x then cancel item 1 of x
end repeat
end if
end cancelThisMsg
So now that I've hung myself please use the Message Box using pending messages (5th icon over) to watch the messages being sent and canceled. At least I can comfort myself in that you'll get a grasp of the messages.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
sturgis
- Livecode Opensource Backer

- Posts: 1685
- Joined: Sat Feb 28, 2009 11:49 pm
Post
by sturgis » Wed May 01, 2013 2:14 am
Hey its not a hanging offense! Polling can be very useful. (though my example uses 2 ticks delay and 6 ticks is probably good enough)
At least I hope its not a hanging offense since our methods are pretty much the same. (The only difference being in how we stop the loop)
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Wed May 01, 2013 2:37 am
Interesting sturgis, I didn't see your post but normally phpBB shows you when someone has posted something before you post again.
One thing we left out.
palanolho, controlKey is synonymous with commandKey so this will work in Mac or Win.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!