command click move 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
billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

command click move window

Post by billworld » Wed Mar 07, 2012 7:50 am

I need some help getted started. I'm not finding the answer readily in the docs.

How do you trigger an event based on a mousedown combined with holding down the command key? I can't figured out how to use mousedown together with commandkeydown.

Ultimately I'd like to code the ability to command mouse click drag a window. It sure would help to see some code which does exactly that.

Thanks!

Bill

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: command click move window

Post by Dixie » Wed Mar 07, 2012 9:31 am

Bill..

Code: Select all

on mouseDown
   if the commandkey is down then
      beep
   end if
end mouseDown
To drag a stack window around your screen, should you not wish to use the windows' title bar...

Code: Select all

on mouseDown
   -- place the window into the MacOS X dock
   if the optionKey is down then
      set the iconic of this stack to true
      exit mouseDown
   end if
   
   
   -- drag the window around the screen
   if the commandKey is down then
      -- find the position of the window and the mouse
      put (item 1 of the loc of this stack) - (item 1 of globalLoc(the mouseLoc)) into hdiff
      put (item 2 of the loc of this stack) - (item 2 of globalLoc(the mouseLoc)) into vdiff
      
      -- set the position of the window relative to where the mouse has been dragged
      repeat until the mouse is "up"
         set the loc of this stack to (item 1 of globalLoc(the mouseLoc) + hdiff),(item 2 of globalLoc(the mouseLoc) + vdiff)
      end repeat
   end if
end mouseDown
be well

Dixie

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

Re: command click move window

Post by Klaus » Wed Mar 07, 2012 11:48 am

Hi Bill,

please only open ONE thread for ONE issue, thanks!
Will delet the doublepost!


Don't think too complicated! :D
Try to explain the problem in plain english and you have the solution in LiveCode!

OK, you want to do something "on mousedown" but only when the COMMAND key being held = "down", right?
So just tell LiveCode:

Code: Select all

on mousedown
  if the commandkey = "down" then
    ## do your stuff here
  end if
end mousedown
And welcome to the forum!


Best

Klaus

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Re: command click move window

Post by billworld » Wed Mar 07, 2012 2:46 pm

Thanks for deleting the double post. I had looked for a way to do this myself and didn't find it. I had gone back in my browser to try and locate a post I had saved as "draft" as it wasn't coming up under "view your posts' and I couldn't readily find it elswhere. That act of going back in the browser caused the post to be resubmitted. I'd suggest someone building a routine to prevent this from happening. Where are my draft posts stored?

Regarding my commandkey problem and "not thinking too complicated", well the frustrating thing is that my attempts at using the following code failed:

on mouseDown
   if commandkey is down then
      answer "yeah"
   end if
end mouseDown

Eivdently "the" is required in front of "commandkey" to make it work. I wasn't aware of the strictness of using "the" in this context. I also struggled with not getting "commandKeyDown" to work either as the following doesn't work.

on mouseDown
   if commandkeydown then
      answer "yeah"
   end if
end mouseDown

It compiles but doesn't work. Is this because commandkeydown is a message and not a function? I'm not clear on said difference yet.

Inserrting "the" in front of "commandkey is down" works. Thanks for the help.

Things like this make coding complicated when the expected behavior doesn't work. An English-like language is only simple when you know all the idiosyncrocies in which it really isn't so English-like.

But maybe there's a rule somewhere I haven't read yet which says "the" must precede any function? Is that the case that such a rule exists?

Thanks for the code snippet.

Klaus wrote:Hi Bill,

please only open ONE thread for ONE issue, thanks!
Will delet the doublepost!


Don't think too complicated! :D
Try to explain the problem in plain english and you have the solution in LiveCode!

OK, you want to do something "on mousedown" but only when the COMMAND key being held = "down", right?
So just tell LiveCode:

Code: Select all

on mousedown
  if the commandkey = "down" then
    ## do your stuff here
  end if
end mousedown
And welcome to the forum!


Best

Klaus

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Re: command click move window

Post by billworld » Wed Mar 07, 2012 2:49 pm

Excellent Dixie. That's exactly what I needed. Thanks much!
Dixie wrote:Bill..

Dixie

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

Re: command click move window

Post by Klaus » Wed Mar 07, 2012 3:08 pm

Hi Bill,

using "the commandkey" is quering a property, which can be UP od DOWN.
...
if THE commandkey = "down" then
...
"commandkeydown" is a function and requires parenthesis:
...
if commandkeydown() = true then
...
In LiveCode there are many ways to skin a cat :D
But I have no idea where the "save draft" gest saved 8)

Best

Klaus

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Re: command click move window

Post by billworld » Wed Mar 07, 2012 3:34 pm

Is "the" required in front of functions?

"commandKey" is documented as a function.

"commandKeyDown" is documented as a message.

Believe it or not I spent a fair amount of time with the docs on this before posting.

Your point about "commandKeyDown" being a function requiring parens is confusing on three counts.
1) It is documented as a message.
2) The code examples in the documentation do NOT include parens
3) It compiles fine without parens

I had tried the following which doesn't compile as "the" is the problem (both with and without parens after the commandKeyDown message).

Code: Select all

on mouseDown
   if the commandkeydown() then
      answer "yeah"
   end if
end mouseDown

on mouseDown
   if the commandkeydown then
      answer "yeah"
   end if
end mouseDown
Dropping "the" in front of commandkeydown gets the code to compile but then it doesn't work. None of the variants below work. I don't know why, Can someone please explain it to me?

Code: Select all

on mouseDown
   if commandkeydown then
      answer "yeah"
   end if
end mouseDown

on mouseDown
   if commandkeydown() then
      answer "yeah"
   end if
end mouseDown

on mouseDown
   if commandkeydown() is true then
      answer "yeah"
   end if
end mouseDown

Anyone confused yet?

Not trying to be difficult here. Just pointint out how a newcomer approaches all of this. And, I'm experienced in programming.

What are the rules for preceding functions or messages with "the" and using parens as the suffix? Seems pretty confusing to me at this point. And said confusion is corroborated by contradictory points made here even by an experienced LiveCode programmer (not knocking you Klaus, just pointing things out as confusing and seeking clarification on rules!).
Klaus wrote:Hi Bill,

using "the commandkey" is quering a property, which can be UP od DOWN.
...
if THE commandkey = "down" then
...
"commandkeydown" is a function and requires parenthesis:
...
if commandkeydown() = true then
...
In LiveCode there are many ways to skin a cat :D
But I have no idea where the "save draft" gest saved 8)

Best

Klaus

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

Re: command click move window

Post by Klaus » Wed Mar 07, 2012 3:54 pm

Hi Bill,

sorry, my fault, I mixed them up a bit...

OK, FUNCTIONS always require parens () and NOT a preceeding THE.

"commandkey", like some other build-in functions, can be used in both ways:
1. like a function:
put commandkey() into tCommandKey
2. like a property:
put THE commandkey into tCommandKey

"CommandkeyDown tKey" is indeed a message and can thus not be used in other scripts but only in its own handler:

Code: Select all

on commandKeyDown theKey -- make Command-5 go back
  if theKey = "5" then 
    answer "5"
  else
    pass commandkeydown
end commandKeyDown
So this should work:

Code: Select all

on mouseDown
   if commandkey() = "down" then
      answer "yeah"
   end if
end mouseDown

on mouseDown
   if the commandkey = "down" then
      answer "yeah"
   end if
end mouseDown

Best

Klaus

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Re: command click move window

Post by billworld » Wed Mar 07, 2012 4:03 pm

Thanks Klaus for clarification on rules. I get the message and should function better now! :D

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

Re: command click move window

Post by Klaus » Wed Mar 07, 2012 4:16 pm

Hi Bill,

good boy! :D

You can get a good overview of LiveCode by checking these stacks:
http://www.runrev.com/developers/lesson ... nferences/


Best from germany

Klaus

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Re: command click move window

Post by billworld » Wed Mar 14, 2012 12:48 am

I've not having success yet adapting the command-drag window code nicely provided here to a group. I need to figure out how to code a generalized routine that can apply to any group of objects set to be command-click-draggable. The code below doesn't work starting with the "put item 1of the location..." line. I'm likely not referencing the current selected group propertly. Thanks for any help on this.

Code: Select all

on mouseDown
      -- drag the group around the screen
      if the commandKey is down then
      
            -- find the position of the window and the mouse
            put item 1 of the location of this group into hdiff
            put item 2 of the location of this group into vdiff
            
            -- set the position of the group relative to where the mouse has been dragged
            repeat until the mouse is "up"
                  set the loc of this group to (item 1 of globalLoc(the mouseLoc) + hdiff),(item 2 of globalLoc(the mouseLoc) + vdiff)
            end repeat
      end if
end mouseDown

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: command click move window

Post by Dixie » Wed Mar 14, 2012 1:15 am

Hi Bill...

You started off by asking how to drag a window around using the mouse & commandKey...
But to drag a group around inside a window, in conjunction with the commanKey, is much easier... :D

in the script of the group...

Code: Select all

on mouseDown
   if the commandKey is down then
      grab me
   end if
end mouseDown
be well

Dixie
Attachments
dragGroup.livecode.zip
(950 Bytes) Downloaded 216 times

billworld
Posts: 188
Joined: Sat Oct 25, 2008 12:32 am

Re: command click move window

Post by billworld » Wed Mar 14, 2012 1:26 am

Whoa! I like the simplicity in that. I'm grabbed! Thanks much Dixie.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”