How to disable mouse click (and then enable it)

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

Post Reply
Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

How to disable mouse click (and then enable it)

Post by Chibling » Wed Sep 16, 2009 9:09 pm

Hello prospective helper,

My question is simple: how do I disable mouse clicking and then enable it?

As part of my program there is a visual demonstration where I do not want the user to click (it tends to mess up a slidebar or they can click a hidden button).

After this demonstration I would like to re-enable mouse click.

So I am thinking something along the lines of:

Code: Select all

on Mouseup
set mouseclick to false
end Mouseup
and then after the demonstration...

Code: Select all

 on Mouseup
set Mouseclick to true
end Mouseup
Of course "mouseclick" is something I made up...

Any help is much appreciated,

-Brandon

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Location: Kent, UK
Contact:

Post by gyroscope » Wed Sep 16, 2009 10:05 pm

Hi Brandon,

I guess one way would be to set up a global variable in the main stack script.

Code: Select all

global gToggle
put 0 into gToggle
for instance.

Somewhere in your code which can trap when the visual demonstration is about to start, put the same as above.

And when it's to finish, put:

Code: Select all

global gToggle
on ----your handler
put 1 into gToggle
end ----your handler
And in each of your controls, buttons,etc, put:

Code: Select all

global gToggle

on mouseUp
if gToggle = 0 then
exit mouseUp
else
-------your code here
end if
end mouseUp
Another more experienced Forum member might tell you something more straightforward though! But I hope this is helpful to you.

:)

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am
Location: Tampa, FL

Post by acidjazz » Wed Sep 16, 2009 10:52 pm

Brandon,

I don't believe you can actually turn off the mouse, but you can block any clicks from reaching particular objects by placing a large button on top of those objects. Once you've dragged the new button and resized it over your to-be-hidden objects, then in the properties of the new button do this:
  • 1. set the style to transparent button
    2. uncheck autohilite
    3. uncheck show name
    4. uncheck opaque
You'll see the objects underneath, but clicking on them won't have any effect. You may also want to place an empty "on mouseUp" handler in the script of that button to trap the mouseclick message, but it depends on what you're trying to do. Once you are done with the demonstration (which I assume is triggered by a script somewhere) just use the hide command (i.e., hide button "tCoverButton") and everything underneath should work again.

Alternately, you can use the disable command for each object. You'll still be able to see them, although they'll be grayed out. When you want them turned back on again you use the enable command.

Good Luck!
AcidJazz

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Thank you both for the fast replies

Post by Chibling » Wed Sep 16, 2009 11:13 pm

Hey thanks guys for the fast reply,

I have decided to go with the "disable" and "enable" route - this seems to solve the issues I was having. So I will disable the hidden objects and when I reveal them I will enable them. I suppose I was under the impression that hiding an object also disabled it.

Again,

Thank you,
I cannot express enough how glad I am to have this forum - very helpful for newbs such as myself - but it is only helpful due to wonderful people such as yourselves.

-Brandon

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am
Location: Tampa, FL

Post by acidjazz » Thu Sep 17, 2009 1:28 am

Brandon,
My understanding has always been (and I just tested it, and confirmed) that if you hide a control you shouldn't be able to click on it. How exactly were you hiding these particular controls? What did you click in the properties box? This is for my benefit if you don't mind, as I realize you're happy with the current solution to your problem.

AcidJazz

Chibling
Posts: 21
Joined: Thu Jul 16, 2009 9:05 pm

Post by Chibling » Thu Sep 17, 2009 4:25 am

Hey AcidJazz,

It turns out that although using disable has helped with a problem with my scrollbars - the button is still clickable while my scroll bar demonstration is going on.

I will post the code for my "experiment" card - I think because the code is under my "on experiment" handler (if that is the right term) that it is not working properly.

Code: Select all

global thepath, photopath, datapath, imagelist, Data, voicelist, response, soundpath, listened, responseTime, fName, stimlist, trialnum, responseVal

local maxTrial

on openCard
  hide image "Photo"
  hide player "Voices"
  hide scrollbar "Slider"
  hide scrollbar "Slider2"
  hide button "Next"
  hide button "Replay"
  hide image "fixation"
  hide fld "EndofTime"
  hide fld "EndofExperiment"
  
  put 72 into maxTrial
  put 1 into trialnum
  
  beginExperiment
  
end openCard

on beginExperiment
   
   get flushevents("all")
  put 0 into response
  put 0 into listened
   
  if trialnum <= maxTrial then
    show image "fixation"
    wait 1 second
    hide image "fixation"
     
    set the itemdelimiter to tab
    set the filename of player "Voices" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices2" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices3" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices4" to soundpath&item 7 of line trialnum of stimlist&".wav"
    set the filename of player "Voices5" to soundpath&item 7 of line trialnum of stimlist&".wav"
    
    
    set the filename of image "Photo" to empty
     
    show image "photo"
    show scrollbar "Slider"
    
put random (2) into donkey

if donkey = 1 then
start player "Voices2"
disable scrollbar "Slider2" 
disable button "Next"
disable button "Replay"
put 0 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25+x&".bmp"
  set the thumbposition of scrollbar "slider" to 25+x
  wait 8 milliseconds
  add 1 to x
end repeat
 
put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&50-x&".bmp"
  set the thumbposition of scrollbar "slider" to 50-x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices3"


put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp"
  set the thumbposition of scrollbar "slider" to 25-x
  wait 8 milliseconds
  add 1 to x
end repeat
 
put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp"
  set the thumbposition of scrollbar "slider" to x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices4"
end if

if donkey = 2 then
 start player "Voices2"
 disable scrollbar "Slider2"
 disable button "Next"
 disable button "Replay"
put 0 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25-x&".bmp"
  set the thumbposition of scrollbar "slider" to 25-x
  wait 8 milliseconds
  add 1 to x
end repeat

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&x&".bmp"
  set the thumbposition of scrollbar "slider" to x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices3"

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&25+x&".bmp"
  set the thumbposition of scrollbar "slider" to 25+x
  wait 8 milliseconds
  add 1 to x
end repeat

put 1 into x
repeat until x>25
  set the filename of image "photo" to photopath&item 6 of line trialnum of stimlist&"-"&50-x&".bmp"
  set the thumbposition of scrollbar "slider" to 50-x
  wait 8 milliseconds
  add 1 to x
end repeat
start player "Voices4"

end if
 
 set the itemdelimiter to tab
 put donkey into item 20 of line trialnum of stimlist 
 
show button "Next"
show button "Replay"
 
hide scrollbar "slider"
set the thumbpos of scrollbar "slider2" to 25
enable scrollbar "slider2"
show scrollbar "slider2"
enable button "Next"
 enable button "Replay"

 
put the milliseconds into t1
 
 send "timeout" to me in 15 seconds 

wait until response = 1 or timeout with messages
 
if response = 1 then
  put the milliseconds into t2
  put t2 - t1 into responseTime
end if

set itemdelimiter to ","
put item 1 of the pendingMessages into iD
cancel iD
 
set the itemdelimiter to tab 
 
saveData responseTime
 
saveChoice
 
hide image "Photo"
hide player "voices"
hide scrollbar "Slider"
hide scrollbar "slider2"
hide button "Next"
hide button "Replay"
hide image "fixation"
hide fld "EndofTime"
hide fld "EndofExperiment"
 
set the itemdelimiter to tab
put trialnum into item 1 of line trialnum of stimlist
 
add 1 to trialnum
 
beginExperiment
 
else
  show field "EndofExperiment"
  wait 5 seconds
  put stimlist into field "Data" of cd "data"
  put stimlist into data
  go to card "data"
  
  put the internet date into y
  put return&"Trialnum"&tab&"Condition"&tab&"Age"&tab&"Language"&tab&"Sex"&tab&"ImageName"&tab&"WordName"&tab&"Con1"&tab&"Vow1"&tab&"Con2"&tab&"Vow2"&tab&"Wordtype"&tab&"1stcontype"&tab&"RealWord?"&tab&"#Replays"&tab&"RT"&tab&"ResponseValue"&tab&"ResponseType"&tab&"Magnitude"&tab&"MvDirection" after y
  put "file:"&DataPath&"D"&the ticks into fName
  put y&return&Data into URL fName
   
end if
end beginExperiment

on timeout

hide image "Photo"
  hide player "voices"
  hide scrollbar "Slider"
  hide scrollbar "Slider2"
  hide button "Next"
  hide button "Replay"
  show field "EndofTime"
  wait 3 seconds 
  hide field "EndofTime"
  
  set the itemdelimiter to tab
  put trialnum into item 1 of line trialnum of stimlist
  put listened into item 15 of line trialnum of stimlist
  put "T-O" into item 16 of line trialnum of stimlist
put "T-O" into item 17 of line trialnum of stimlist
put "T-O" into item 18 of line trialnum of stimlist
put "T-O" into item 19 of line trialnum of stimlist
  
  add 1 to trialnum
  beginExperiment
  
end timeout


on saveChoice
  set the itemdelimiter to tab
  if response = 1 then
    put the thumbpos of scrollbar "slider2" into item 17 of line trialnum of stimlist
    put the thumbpos of scrollbar "slider2" into ResponseVal
put listened into item 15 of line trialnum of stimlist
put ResponseVal-25 into item 19 of line trialnum of stimlist
if ResponseVal=25 then
  put "M" into item 18 of line trialnum of stimlist
  end if
if ResponseVal>25 then 
put "R" into item 18 of line trialnum of stimlist
  end if
  if ResponseVal<25 then 
  put "J" into item 18 of line trialnum of stimlist
  end if
end if  
end saveChoice

on saveData x
  set the itemdelimiter to tab
  put x into item 16 of line trialnum of stimlist
end saveData x
I know the coding is a lot and it is messy... but maybe this will be illuminating from your perspective.

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am
Location: Tampa, FL

Post by acidjazz » Thu Sep 17, 2009 5:19 am

Very interesting. I'm an experimental psychologist (social cognition) at USF St. Petersburg, so I'm always interested in how others use runrev to do research. Now, without seeing your demonstration in practice it's still not entirely clear what the problem is; Still seems that if you put a transparent button over your scrollbars, you should be fine. However, I could be misunderstanding the problem... Would you be willing to share with me your .rev file, so I could take a look? If you wish to converse offsite, my email is pezzo (at) mail (dot) usf (dot) edu.

Mark

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Thu Sep 17, 2009 8:52 am

Hi Brandon,

the most effective way to "disable" mouseclicks may be a frontscript!

Do this:
1. Create an invisible button "nomouseclicks" with this script:

Code: Select all

on mouseup
  ## Yes, do nothing :)
end mouseup
Add an empty "mousedown" handler or whatever you need to suppress in that script!
2. Now you can add this line to the beginning of your "beginexperiment " handler
...
insert script of btn "nomouseclicks" of cd X into front
...
3. Whenever the experiemtn ends, add this line:
...
remove script of btn "nomouseclicks" of cd X from front
...

That's it!
This way, all "mousecliks" will go to this script first and since you do NOT "pass mouseup",
all the clicks will go into data nirvana :-)
No need to hide of modify any button that has a "mouse" script of any kind!

Maybe that will work for you.


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Post by FourthWorld » Thu Sep 17, 2009 6:27 pm

Klaus' suggestion of using a frontScript is an excellent one, and frontScripts are so handy they're good to know about.

The only consideration I would add here is that the user may wonder why some clicks are processed and others not, and may confuse the behavior with a bug.

Of course that perception will depend on the nature of the layout, but if that's a risk in yours you could consider putting all the controls in a group an simply disabling the group when you don't want clicks processed, enabling it again when you do.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”