Attempting to bind binds to all keys #1

Open
tpitale opened this Issue Sep 23, 2009 · 9 comments

Comments

Projects
None yet
6 participants
@tpitale

tpitale commented Sep 23, 2009

No matter what I bind, every keydown is bound to a function. I have no idea why this happens. Using jQuery 1.3.

@chrisblow

This comment has been minimized.

Show comment Hide comment
@chrisblow

chrisblow Feb 8, 2010

i also have this problem.

i also have this problem.

@beaudesigns

This comment has been minimized.

Show comment Hide comment
@beaudesigns

beaudesigns Jul 15, 2010

This happens when you don't include the jquery file in your document's header.

Make sure it's included.

This happens when you don't include the jquery file in your document's header.

Make sure it's included.

@santiycr

This comment has been minimized.

Show comment Hide comment
@santiycr

santiycr Nov 1, 2010

No matter what I do, I keep getting this failure. I made sure the jquery is loaded right before hotkeys, then I loaded hotkeys, then my own script with the hotkey assignments. No way to avoid it from happening.

santiycr commented Nov 1, 2010

No matter what I do, I keep getting this failure. I made sure the jquery is loaded right before hotkeys, then I loaded hotkeys, then my own script with the hotkey assignments. No way to avoid it from happening.

@santiycr

This comment has been minimized.

Show comment Hide comment
@santiycr

santiycr Nov 1, 2010

WTF, I don't know if it's just me, or this plugin is just useless. Here's my source code, everytime I press a key, the function is called one time for each time I bind a keydown:

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="jquery.hotkeys.js"></script>
        <script type="text/javascript">
            function alertHotkey(){
                alert("called!");
            }
            $(function(){
                $(document).bind('keydown', "a", alertHotkey);
                $(document).bind('keydown', "g", alertHotkey);
                $(document).bind('keydown', "l", function(){});
            })
        </script>
    </head>
    <body>
        <h1>bleh</h1>
        <p>lorem ipsum</p>
    </body>
</html>

santiycr commented Nov 1, 2010

WTF, I don't know if it's just me, or this plugin is just useless. Here's my source code, everytime I press a key, the function is called one time for each time I bind a keydown:

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="jquery.hotkeys.js"></script>
        <script type="text/javascript">
            function alertHotkey(){
                alert("called!");
            }
            $(function(){
                $(document).bind('keydown', "a", alertHotkey);
                $(document).bind('keydown', "g", alertHotkey);
                $(document).bind('keydown', "l", function(){});
            })
        </script>
    </head>
    <body>
        <h1>bleh</h1>
        <p>lorem ipsum</p>
    </body>
</html>
@gil

This comment has been minimized.

Show comment Hide comment
@gil

gil May 25, 2012

@santiycr Your code is incorrect. You'll need jQuery 1.6+ and your bind should use namespaces. This should work:

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
        <script type="text/javascript" src="https://raw.github.com/tzuryby/jquery.hotkeys/master/jquery.hotkeys.js"></script>
        <script type="text/javascript">
            function alertHotkey(){
                alert("called!");
            }
            $(function(){
                $(document).bind("keydown.a", alertHotkey);
                $(document).bind("keydown.g", alertHotkey);
                $(document).bind("keydown.l", function(){});
            })
        </script>
    </head>
    <body>
        <h1>bleh</h1>
        <p>lorem ipsum</p>
    </body>
</html>​

gil commented May 25, 2012

@santiycr Your code is incorrect. You'll need jQuery 1.6+ and your bind should use namespaces. This should work:

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
        <script type="text/javascript" src="https://raw.github.com/tzuryby/jquery.hotkeys/master/jquery.hotkeys.js"></script>
        <script type="text/javascript">
            function alertHotkey(){
                alert("called!");
            }
            $(function(){
                $(document).bind("keydown.a", alertHotkey);
                $(document).bind("keydown.g", alertHotkey);
                $(document).bind("keydown.l", function(){});
            })
        </script>
    </head>
    <body>
        <h1>bleh</h1>
        <p>lorem ipsum</p>
    </body>
</html>​
@santiycr

This comment has been minimized.

Show comment Hide comment
@santiycr

santiycr May 28, 2012

Thanks @gil. FWIW, my comment was made 2 years ago, 1.6 wasn't out there and I believe the api changed since then. I'll keep it in mind if I need this plugin again. :)

Thanks @gil. FWIW, my comment was made 2 years ago, 1.6 wasn't out there and I believe the api changed since then. I'll keep it in mind if I need this plugin again. :)

@gil

This comment has been minimized.

Show comment Hide comment
@gil

gil May 29, 2012

@santiycr Ohh, I didn't realize when I replied. I was reading all the issues before forking the code and I decided to help. Well, good to know it's working if you ever need it again. ;)

gil commented May 29, 2012

@santiycr Ohh, I didn't realize when I replied. I was reading all the issues before forking the code and I decided to help. Well, good to know it's working if you ever need it again. ;)

@santiycr

This comment has been minimized.

Show comment Hide comment
@santiycr

santiycr May 29, 2012

@gil good to know indeed. I'll keep an eye in your fork.

@gil good to know indeed. I'll keep an eye in your fork.

@chrisdpeters

This comment has been minimized.

Show comment Hide comment
@chrisdpeters

chrisdpeters Sep 5, 2012

I know this is a pretty old issue, but I was having the same issue as @tpitale and @unthinkingly, but I was able to resolve it.

How did I fix it? I took my $(document).bind(...) call out of the $(document).ready(...) block. Before doing that, every key triggered the event, not just my specification of keydown.ctrl_e.

Hope that helps others. FWIW, the resolution to this issue may be to add this bit of information to the README. Even if you assume to know how bind works, this was a detail that took me a couple sessions of debugging/frustration to uncover. Sometimes these sorts of things slip through the cracks in my cranium.

I know this is a pretty old issue, but I was having the same issue as @tpitale and @unthinkingly, but I was able to resolve it.

How did I fix it? I took my $(document).bind(...) call out of the $(document).ready(...) block. Before doing that, every key triggered the event, not just my specification of keydown.ctrl_e.

Hope that helps others. FWIW, the resolution to this issue may be to add this bit of information to the README. Even if you assume to know how bind works, this was a detail that took me a couple sessions of debugging/frustration to uncover. Sometimes these sorts of things slip through the cracks in my cranium.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment