Detect if key is pressed

4 posts, 1 answers
  1. Alex Galie
    Alex Galie avatar
    22 posts
    Member since:
    Dec 2009

    Posted 13 Jan 2010 Link to this post

    Hello all,

    I'm currently using the RAD controls for silverlight and I'd like to implement the following: when I drag an item from one place to another, detect if a key, for example shift, is pressed, while dragging that is. Depending on this, I want to change the drag cue, if possible, and also, more importantly, choose what logic to follow when dropping the item.

    Is this achievable ?

    Thanks!
  2. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 13 Jan 2010 Link to this post

    Hello Alex Galie,

    Yes, it is possible to detect if any of the special keys is pressed by checking Keyboard.Modifiers.

    If you assign a drag cue element to the e.Options.DragCue in any of the DragDrop handlers, you will be able to access it and change any of its properties to give it a different look.

    I can suggest using the TreeViewDragCue control that is used by the TreeView for its DragDrop. This class has built-in properties that help you display DragDrop information.

    I am attaching an example that shows how this control can be used in custom scenarios. The particular example does not show integration with the keyboard modifiers so do get back to us if you have problems implementing this.

    All the best,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Alex Galie
    Alex Galie avatar
    22 posts
    Member since:
    Dec 2009

    Posted 14 Jan 2010 Link to this post

    Thanks Miroslav, it works.

    There is a small issue however: where should I test for Keyboard.Modifiers to reflect the changes in "real time" ? Right now, I've put it in DropInfo handler and it's something like this:

    if (e.Options.Status == DragStatus.DropPossible) 
        if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) 
        { 
                // change cue here 
            } 
     

    If I just hold the dragged item still and press Control, nothing happens, I have to move it a bit for the cue to change. Is there a way to change the cue right when Control is pressed and I'm not moving the dragged item around ?

    Don't know if it's clear, hope you understand what I'm trying to say :)


    Thanks,
    Alex
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 15 Jan 2010 Link to this post

    Hello Alex Galie,

    Yes, it is clear what you are trying to achieve.

    To care for this case you may handle the KeyDown event in your application root and access the DragDrop options object from RadDragAndDropManager.Options. This is the same options object that you will get in the event handler.

    In fact you can move most of your update logic there apart from the things that happen on DropComplete.

    You can use RadDragAndDropManager.IsDragging to check whether updates are necessary.

    Please note that events may not always reach the application visual roots, especially if the happen in popups. Do test this if it matters in your case. 

    Hopefully this will work for you.

    Greetings,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top