Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal keybinding implementation inquery #115

Closed
khalidchawtany opened this issue Jul 12, 2016 · 16 comments
Closed

Modal keybinding implementation inquery #115

khalidchawtany opened this issue Jul 12, 2016 · 16 comments
Labels

Comments

@khalidchawtany
Copy link

  • Version: 2.2 (33)
  • macOS: 10.11.5

First of all this is not an issue.

I want to have a modal keybinding to operate Phoenix. Ultimately, I wan to have a mode which could be activated with a HYPER and then terminated with ESC. When inside that mode, pressing single letters should be enough to trigger phoenix actions (No HYPER press needed till ESC is pressed).

Any help is appreciated.

@kasper
Copy link
Owner

kasper commented Jul 12, 2016

Cool! Have you tried implementing this? There’s at least two strategies you could apply here:

  1. Bind HYPER, ESC and all action keys
  2. Store references to the action keys (from new Key(...))
  3. Disable all action keys immediately
  4. When HYPER is pressed, enable all action keys
  5. When ESC is pressed, disable all action keys

Or you could:

  1. Bind HYPER and ESC keys
  2. When HYPER is pressed, bind all action keys (with new Key(...) or Key.on(...))
  3. Store references to the action keys (references or identifiers)
  4. When ESC is pressed, release all action keys

@khalidchawtany
Copy link
Author

Thanks, I will try you suggestion.

I have taken a look at a modal config. However, it was for a previous version. I was wondering if there is any new stuff that would make it easier to implement.

@kasper
Copy link
Owner

kasper commented Jul 12, 2016

@khalidchawtany Let me know how it goes! Key.on(...) and Key.off(...) may help with the second strategy, but I would say the first one is easier.

@khalidchawtany
Copy link
Author

khalidchawtany commented Jul 12, 2016

@kasper I have found that bound keys are not repeated when pressed and hold. You have to press and release each time to make it trigger :(

You can test it using this:

var counter = 0;
Key.on('p', [],  function() { alert(counter++); });

alert is modal showing the passed message.

@kasper
Copy link
Owner

kasper commented Jul 13, 2016

@khalidchawtany That is by design (kEventHotKeyPressed). What would you use this for?

@khalidchawtany
Copy link
Author

khalidchawtany commented Jul 13, 2016

I want to micro-manage window movements and resizes. I want to move a window 10 pixels to the left on pressing h, holding h should move it multiples of 10 pixels.

@kasper
Copy link
Owner

kasper commented Jul 13, 2016

@khalidchawtany Let me see if this is an easy fix.

@khalidchawtany
Copy link
Author

I really appreciate your hard work 👍

@kasper
Copy link
Owner

kasper commented Jul 13, 2016

@khalidchawtany Unfortunately, there is no automated way and it seems this has to be implemented with a timer. 😭

@mafredri
Copy link
Contributor

@kasper if it's any comfort, I might have some uses for this as well. I've ran into this a couple of times but thought I'd just live with it :). And like @khalidchawtany said, your work is appreciated, you've been on fire lately ^_^.

@kasper
Copy link
Owner

kasper commented Jul 13, 2016

@mafredri @khalidchawtany Oh well. What would be a suitable interval? 60 times per second? You could then throttle that to your needs with for example _.throttle(...).

@khalidchawtany
Copy link
Author

That would be awesome :)

@mafredri
Copy link
Contributor

That would be more than enough in my opinion. How fast do we think Phoenix needs to be able to respond? I think a suitable range would be between 20 - 50ms, with 20, it would be 1000 / 20 = 50 and with 50ms it would be 1000 / 50 = 20. So maybe 50x / second and we get a nice round number (20ms)?

On the other hand, how precise would the timing be, this being JS and all, would other operations block, etc?

@kasper
Copy link
Owner

kasper commented Jul 13, 2016

@mafredri I’ll first try with 0,05 seconds.

@kasper
Copy link
Owner

kasper commented Jul 13, 2016

Actually, you can get it from the system with [NSEvent keyRepeatInterval]. Seems to be 0.083333333333333329.

@kasper
Copy link
Owner

kasper commented Jul 13, 2016

Issue #119.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants