[CLOSED] KeyMap delay

  1. #1

    [CLOSED] KeyMap delay

    Support,

    How can I add a 250 millisecond delay so if they hold down the F button, we only focus once.

    thanks
    /Z

            <ext:KeyMap runat="server" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}" >
                <Binding>
                    <ext:KeyBinding Handler="#{TriggerField1}.focus();" >
                        <Keys>
                            <ext:Key Code="F"  />
                        </Keys>
                    </ext:KeyBinding>
                </Binding>
            </ext:KeyMap>
  2. #2
    Hello @Z!

    You'd have to handle the keydown and keyup events. Keydown will maintain the key pressed state, and keyup will update the state as released. Well, this is at least one of the possible ways, and focus in using the ext:KeyMap component.

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Handle key holding.</title>
        <script type="text/javascript">
            var keyState = {
                isDown: false,
                downTime: undefined,
                isHandled: false
            }
    
            function handleKeyDown() {
                if (!keyState.isDown) {
                    Ext.toast("Key is now down.");
                    keyState.isDown = true;
                    keyState.downTime = new Date();
                    keyState.isHandled = false;
                } else {
                    if (!keyState.isHandled && (new Date() - keyState.downTime) > 250) {
                        Ext.toast("Key held for 250ms.");
                        keyState.isHandled = true;
                    }
                }
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:Label runat="server" Text="Hold the 'f' key for 250ms." />
    
        <ext:KeyMap runat="server" EventName="keydown" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}" >
            <Binding>
                <ext:KeyBinding Handler="handleKeyDown()" >
                    <Keys>
                        <ext:Key Code="F" />
                    </Keys>
                </ext:KeyBinding>
            </Binding>
        </ext:KeyMap>
        <ext:KeyMap runat="server" EventName="keyup" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}" >
            <Binding>
                <ext:KeyBinding Handler="keyState.isDown = false; Ext.toast('Key released.');" >
                    <Keys>
                        <ext:Key Code="F" />
                    </Keys>
                </ext:KeyBinding>
            </Binding>
        </ext:KeyMap>
    </body>
    </html>
    Hope this helps!
  3. #3
    Hello @Z!

    It's been a while since we responded here, and still no feedback from you. Did the info above about using the keydown/keyup events help you after all? We may mark this thread as closed in 7+ days from now, but you'd still be able to post a follow-up whenever you feel fit.

    Hope the solution above was enough!
    Fabrício Murta
    Developer & Support Expert
  4. #4
    close.
    thxs

Similar Threads

  1. Replies: 6
    Last Post: Sep 04, 2012, 12:59 PM
  2. [CLOSED] Buffer vs Delay
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 07, 2011, 6:34 PM
  3. [CLOSED] Delay on success
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 25, 2010, 6:28 PM
  4. [CLOSED] MessageBox with Delay
    By macap in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 30, 2010, 5:03 PM
  5. [CLOSED] Tooltip delay
    By danielg in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 09, 2009, 2:10 PM

Posting Permissions