Drag & Drop / Copy & Move (Respond to control key presses...)

Posted on 2004-11-27
Last Modified: 2010-04-05
Hi Guys.

I have an app that does drag & Drop. It works great. It looks somewhat like the windows folder explorer. I can move files from folders to folders.

Now I want to add the capability to respond to the Control key to change the behavior from copy to move (i.e. with CONTROL it copes, without CONTROL it moves). Like in many applications.

It seems like quite a common thing to do, but I'm not sure how to do it.

In my app, I have OnStartDrag in the "files" listbox, and then I put the file's ID as the DragObject. The cursor is changed automatically to the "drag" cursor.

Pretty simple so far. But now I'm baffled on how to proceed... how can I intercept the press/depress on Control while draging? I guess I can do it on the dragged-to object (The folders list) only. And then somehow change the cursor and remember that the CONTROL is pressed?

Any advice before I start tackling this?

Question by:mertero
    LVL 12

    Accepted Solution

    You probably want to catch it in the DragDrop event when you let go...

    (Look at explorer - you can change whether shift/ctl are pressed as you drag a file)

    To change the cursor as you go... doesn't the source of the drag/drop keep getting MouseMove events as you drag? (Even after the mouse has left the boundary of the component)... so you can check the button state in MouseMove, if you're dragging, and change the cusros there?
    LVL 27

    Expert Comment

    take a look into my solution at

    your needed part from there (in procedure SetTreeItemTypeSet):

      //First do as want to Move
      Result := [ddtMove];
      //Get Shift Key
      if (GetAsyncKeyState(VK_SHIFT) OR $FFFF) = -1 then
        Result := Result + [ddtSort] - [ddtMove];

      //Get Control Key
      if (GetAsyncKeyState(VK_CONTROL) OR $FFFF) = -1 then
        Result := Result + [ddtCopy] - [ddtMove];

    hope you get it

    meikl ;-)


    Author Comment

    Thanks guys.

    I had to do some tweaking myself (Chagne the dragged OBJECT was the key) but you got me started in the right direction.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now