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

Mouse keys #90

Closed
loyoan1 opened this issue May 5, 2016 · 13 comments
Closed

Mouse keys #90

loyoan1 opened this issue May 5, 2016 · 13 comments
Assignees
Labels
Milestone

Comments

@loyoan1
Copy link

loyoan1 commented May 5, 2016

Hey,

is it possible to get mouse keys available?

@kasper
Copy link
Owner

kasper commented May 5, 2016

Hello! If you mean that you would like to use function buttons on your mouse to trigger Phoenix, you can usually use the driver software for your mouse to rebind those buttons to a custom keyboard shortcut. Then you can bind that shortcut with Phoenix. Would that help?

@loyoan1
Copy link
Author

loyoan1 commented May 5, 2016

I actually want to check in javascript if the mouse button is up or down. Is there a way to check that?

@kasper
Copy link
Owner

kasper commented May 6, 2016

Ah, I see. There’s currently no way to determine that, but I presume it would be possible. Could you describe how you would use this?

@loyoan1
Copy link
Author

loyoan1 commented May 6, 2016

I am trying to implement a window snap feature and like to know, if the
user has released the mouse button or not. The window should only snap at
the edge, if the mouse button is released.
Kasper Hirvikoski notifications@github.com schrieb am Fr., 6. Mai 2016 um
08:30:

Ah, I see. There’s currently no way to determine that, but I presume it
would be possible. Could you describe how you would use this?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#90 (comment)

@kasper
Copy link
Owner

kasper commented May 6, 2016

Right, so you’re presumably listening to the windowDidMove-event? For now, you could use something like the debounce-function from Underscore to determine when an event has stopped occuring. I think that would be the easiest way to implement a snapping feature…

I’ll think about how we could support mouse events in the future.

@kasper kasper added the feature label May 6, 2016
@kasper kasper added this to the future milestone May 6, 2016
@kasper kasper self-assigned this May 6, 2016
@loyoan1
Copy link
Author

loyoan1 commented May 6, 2016

Sounds great! Thanks for the tip using debounce. :)

2016-05-06 10:57 GMT+02:00 Kasper Hirvikoski notifications@github.com:

Right, so you’re presumably listening to the windowDidMove-event? For
now, you could use something like the debounce
http://underscorejs.org/#debounce-function from Underscore to determine
when an event has stopped occuring. I think that would be the easiest way
to implement a snapping feature…

I’ll think about how we could support mouse events in the future.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#90 (comment)

@kasper
Copy link
Owner

kasper commented May 6, 2016

You’re most welcome. Let me know if you need more help with debounce.

@mafredri
Copy link
Contributor

mafredri commented May 7, 2016

I noticed setTimeout is missing from Phoenix, so I tried, out of interest, to use the underscore debounce (since it uses setTimeout) and noticed that it doesn't work. Phoenix prints out a ReferenceError. Is it supposed to work, am I missing something?

@kasper
Copy link
Owner

kasper commented May 7, 2016

@mafredri Darn, you’re right! I completely forgot it obviously uses setTimeout. JavaScriptCore doesn’t include timing functions, in browsers those are implemented in the DOM.

Nevertheless, Phoenix does support timing functions, check out Phoenix.after and Phoenix.every. I guess you would need to first implement setTimeout with them.

@mafredri
Copy link
Contributor

mafredri commented May 8, 2016

I took a stab at implementing the timeout/interval API for Phoenix. It also fixes the underscore debounce functionality :). Maybe of interest to you @oleic?

I tried to keep it simple, whilst removing the explicit requirement on keeping references to your handlers (when using setTimeout / setInterval).

(function(global) {
    // Keeps references to Phoenix handlers
    var refs = new Set();

    // Add functions on the global object
    global.setTimeout = setTimeout;
    global.clearTimeout = clear;
    global.setInterval = setInterval;
    global.clearInterval = clear;

    function setTimeout(fn, interval) {
        var handler = Phoenix.after(interval / 1000, handleFn);
        refs.add(handler);
        return handler;

        function handleFn() {
            fn();
            refs.delete(handler); // Delete reference after completion
        }
    }

    function setInterval(fn, interval) {
        var handler = Phoenix.every(interval / 1000, fn);
        refs.add(handler);
        return handler;
    }

    function clear(handler) {
        handler.stop(); // Stop the timer immediately
        refs.delete(handler);
    }
})(this);

@kasper
Copy link
Owner

kasper commented May 8, 2016

@mafredri Nice! I think we should add setTimeout and setInterval to the core to enable various timing related functions from Underscore.

@mafredri
Copy link
Contributor

mafredri commented May 8, 2016

I agree, it would make sense to support all functionality of Underscore since it comes bundled! And also, supporting commonly used APIs makes it more fluent to use Phoenix :).

@kasper
Copy link
Owner

kasper commented Jul 5, 2016

I’ve added support for the following mouse events to Phoenix. Others can be added provided they are useful. Interestingly, there doesn’t seem to be any distinction between “down” and “up” with global mouse events. Both are triggered when the click is released — so I’ve only provided the up events. This feature will be released in 2.2.

  • mouseDidMove triggered when the mouse has moved
  • mouseDidLeftClick triggered when the mouse did left click
  • mouseDidRightClick triggered when the mouse did right click

@kasper kasper closed this as completed Jul 5, 2016
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