Keys down while dragging

  • I would like to implement a drag-and-drop where holding the Shift key
    does something different than a normal drag.  How can I get the state
    of the modifier keys without being the active application?  Any help
    would be greatly appreciated.

    --Adam Johnson
  • On Oct 24, 2006, at 6:59 PM, Adam Johnson wrote:

    > I would like to implement a drag-and-drop where holding the Shift key
    > does something different than a normal drag.  How can I get the state
    > of the modifier keys without being the active application?  Any help
    > would be greatly appreciated.

    Does something different when?

    If its when the mouse is released, you can just examine the mouseUp
    event's modifier flags.

    _murat
  • On Oct 24, 2006, at 9:07 PM, Murat Konar wrote:

    >
    > On Oct 24, 2006, at 6:59 PM, Adam Johnson wrote:
    >
    >> I would like to implement a drag-and-drop where holding the Shift key
    >> does something different than a normal drag.  How can I get the state
    >> of the modifier keys without being the active application?  Any help
    >> would be greatly appreciated.
    >
    > Does something different when?
    >
    > If its when the mouse is released, you can just examine the mouseUp
    > event's modifier flags.

    I think what he is asking -- and it is something I, too, would like
    to learn how to do -- is how to change the cursor in the midst of a
    drag (i.e.: before the mouseUp).  Something like when you are
    dragging a file in Finder and you press Option the cursor gets the
    little green '+' (copy instead of move) badge, or if you press Command
    +Option it changes to the curved arrow "Make alias" cursor, etc...

    Apologies, Adam, if I'm putting bytes in your buffer, but as I
    mentioned, I've been wondering about this myself.

    pete
  • http://www.cocoabuilder.com/archive/message/cocoa/2002/6/19/51217

    On 25-Oct-06, at 11:32 AM, Peter Schart wrote:

    > On Oct 24, 2006, at 9:07 PM, Murat Konar wrote:
    >
    >>
    >> On Oct 24, 2006, at 6:59 PM, Adam Johnson wrote:
    >>
    >>> I would like to implement a drag-and-drop where holding the Shift
    >>> key
    >>> does something different than a normal drag.  How can I get the
    >>> state
    >>> of the modifier keys without being the active application?  Any help
    >>> would be greatly appreciated.
    >>
    >> Does something different when?
    >>
    >> If its when the mouse is released, you can just examine the
    >> mouseUp event's modifier flags.
    >
    >
    > I think what he is asking -- and it is something I, too, would like
    > to learn how to do -- is how to change the cursor in the midst of a
    > drag (i.e.: before the mouseUp).  Something like when you are
    > dragging a file in Finder and you press Option the cursor gets the
    > little green '+' (copy instead of move) badge, or if you press
    > Command+Option it changes to the curved arrow "Make alias" cursor,
    > etc...
    >
    > Apologies, Adam, if I'm putting bytes in your buffer, but as I
    > mentioned, I've been wondering about this myself.
    >
    > pete _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/meirmans%
    > 40sympatico.ca
    >
    > This email sent to <meirmans...>
  • On Oct 25, 2006, at 7:32 PM, PGM wrote:

      Sorry, but it's only fair to point out that the link you provided
    does not really apply here.

    >>> On Oct 24, 2006, at 6:59 PM, Adam Johnson wrote:
    >>>
    >>>> I would like to implement a drag-and-drop where holding the
    >>>> Shift key
    >>>> does something different than a normal drag.  How can I get the
    >>>> state
    >>>> of the modifier keys without being the active application?  Any
    >>>> help
    >>>> would be greatly appreciated.

      So for example, you want (during drag) the shift key to cause a
    selection rectangle, rather than a move or something similar, is this
    what you're after?

      In that case, in your mouseDown: or mouseDragged: method, you
    simply ask the event that gets passed to it for its keys, modifiers,
    or whatever you need (see NSEvent for a list of what you can get and
    when/how):

    BOOL hasShiftKeyMask = (([theEvent modifierFlags] & NSShiftKeyMask) !
    = 0);

      ... then use that knowledge wherever appropriate. I'll assume you
    know what to do with drags in general. If not, the list archives and
    cocoadev.com await. ;-)

    --
    I.S.
  • I can't get the mouseDown and mouseUp events because it's not the
    first responder when it's the recipient of a drag.

    On 10/24/06, Murat Konar <murat...> wrote:
    >
    > On Oct 24, 2006, at 6:59 PM, Adam Johnson wrote:
    >
    >> I would like to implement a drag-and-drop where holding the Shift key
    >> does something different than a normal drag.  How can I get the state
    >> of the modifier keys without being the active application?  Any help
    >> would be greatly appreciated.
    >
    > Does something different when?
    >
    > If its when the mouse is released, you can just examine the mouseUp
    > event's modifier flags.
    >
    > _murat
    >
  • On Oct 26, 2006, at 6:07 PM, Adam Johnson wrote:

    > I can't get the mouseDown and mouseUp events because it's not the
    > first responder when it's the recipient of a drag.

    At any given time, you can get the current event by calling [NSApp
    currentEvent].

    _murat
  • On Oct 26, 2006, at 17:08, m wrote:

    > On Oct 26, 2006, at 6:07 PM, Adam Johnson wrote:
    >
    >> I can't get the mouseDown and mouseUp events because it's not the
    >> first responder when it's the recipient of a drag.
    >
    > At any given time, you can get the current event by calling [NSApp
    > currentEvent].

    That only works if your app is in the foreground.  As someone else
    pointed out, the correct API to use when you receive drags in the
    background (which I believe is the OP's question) is
    GetCurrentKeyModifiers().

    Adam Maxwell
  • GetCurrentKeyModifiers() is exactly what i needed. Thanks!

    On 10/26/06, Adam R. Maxwell <amaxwell...> wrote:
    >
    > On Oct 26, 2006, at 17:08, m wrote:
    >
    >> On Oct 26, 2006, at 6:07 PM, Adam Johnson wrote:
    >>
    >>> I can't get the mouseDown and mouseUp events because it's not the
    >>> first responder when it's the recipient of a drag.
    >>
    >> At any given time, you can get the current event by calling [NSApp
    >> currentEvent].
    >
    > That only works if your app is in the foreground.  As someone else
    > pointed out, the correct API to use when you receive drags in the
    > background (which I believe is the OP's question) is
    > GetCurrentKeyModifiers().
    >
    > Adam Maxwell
    >
    >
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today