when the method is called the jquery.Event doesn’t have ‘which’/keyPress field …The use case is when multiple keymaps are associated with one method is there a way to identify which key combination was pressed to get to the method.
Have you tried using the Keybinding Resolver (Cmd+. on OS X and Ctrl+. on other platforms)? It will show you what key Atom saw you press and the command that was triggered because of it.
to clarify this is for the custom package and the requirement is to identify programatically the key pressed. if there are multiple keymaps to the same package method…when the method is called, the arguments passed has jquery.Event but it doesn’t have the keyPress/which to identify which key combination was pressed to get to the method
Why would you have multiple keybindings for one command in your own package? And if you did, why would you need to do something different based on which keybinding is pressed?
For example, in the fuzzy-finder package there are two keybindings for the file picker, Cmd+P and Cmd+T. But they both open the file picker, so you don’t need to know which keybinding is pressed. If a keybinding is supposed to do something different … then map it to a different command. And then you don’t need to know which keybinding is pressed.
if there is a logic around the key combination pressed …what is the way…why wouldn’t the jquery.Event not pass the key pressed…
I don’t know, I’ve never needed to do what you are suggesting. If you could fill in what you’re actually trying to accomplish, I might be able to suggest an easier way of getting it done.
@leedohm I managed to figure out the dynamic key press combination. The purpose is navigate package (heads up --> you need browser-plus package to try this). This allows the users to dynamically set the url in the config file to which to navigate to. the default set up in config right now is
title: 'F1 - Help’
title: 'F1 - Help’
title: 'Stack Overflow Search’
title: 'AtomIO Search’
what this does is …you can press F1 to go the the help using devdocs and ctrl-f1 would take to google help for the word under and stack overflow(ctrl-f2) and atom(ctrl-f3) and the good thing is you can add your own key with a different url…I think this really makes ATOM coool.
The thing right now…I got a issue logged in the github saying the event is not available in the linux OS…I am using the
evt.originalEvent.keyIdentifier for capturing the key combination…I have tested this in window…wondering if you/ anybody can throw some light on this…
Why can’t you have something like this?
# lib/my-package.coffee class MyPackage activate: -> atom.commands.add 'my-package:ctrl-f1', @ctrlF1 atom.commands.add 'my-package:ctrl-f2', @ctrlF2 # etc... ctrlF1: (e) => @actualFunction 'f1', e ctrlF2: (e) => @actualFunction 'f2', e # etc... actualFunction: (keyPressed, e) -> # do something based on the key pressed
# keymaps/my-package.cson 'atom-workspace': 'ctrl-f1': 'my-package:ctrl-f1' 'ctrl-f2': 'my-package:ctrl-f2' # etc...
That is exactly the point of dynamic. You can add your key combination say ctrl-f4 with a different URL . The key combination can be added keymap.cson and the corresponding URL maintained in configuration.coffee in the package.
And it will start to work!!
BTW Were you able to test it.