chieffancypants / angular-hotkeys

Configuration-centric keyboard shortcuts for your Angular apps.
http://chieffancypants.github.io/angular-hotkeys/
MIT License
1.68k stars 248 forks source link

CTRL used to mark copy instead of drag #210

Open checklist opened 8 years ago

checklist commented 8 years ago

Hi,

I want to add to our app the possiblity to switch from drag-n-drop to drag-n-copy when the CTRL button is clicked. I can easily hook to the clicking on the CTRL but I am not sure how to hook to the CTRL keyup. I basically need to tie the CTRL button being pressed to a true/false flag.

So I am using the action as follows:

            combo: 'ctrl'
            action: 'keydown'
            description: 'Use while dragging to make a copy'
            short_description: 'drag-n-copy'
            callback: =>
                drag.startCopy()
        ,
            combo: 'ctrl'
            action: 'keyup'
            description: 'Use while dragging to make a copy 2'
            short_description: 'drag-n-copy 2'
            callback: =>
                drag.endCopy()

But only the keyup is being picked and the keydown is being ignored. It seems like the second mapping overrides the first.

Any help would be appreciated.

Great lib and many thanx!

cyrilgandon commented 7 years ago

Same problem here, did you find a workaround?

checklist commented 7 years ago

nope :-(

aramando commented 7 years ago

I certainly can't see how you would do this without modification of the library. But I wonder if using angular-hotkeys to register this functionality is the best approach? You have presumably got some other code that sets up the drag and drop functionality, so would that not be a more logical place to put additional code that modifies its behaviour? If you're listening for dragStart and dragEnd events you could easily add to their event handlers code to start and stop listening for keyup and keydown events and check those events for the ctrl key.

cyrilgandon commented 7 years ago

Found a workaround, it appears that if you declare the up event before the down, it works. See https://github.com/chieffancypants/angular-hotkeys/issues/150