Is keymap currently broken in ext1 a2? - Ext JS

本文探讨了在ExtJS框架中实现全局快捷键的方法。作者最初尝试使用KeyMap组件但未能成功,原因是容器元素无法接收键盘焦点。通过讨论,找到了解决方案,即利用文档级别的KeyMap并结合Ctrl键实现应用范围内的快捷键导航。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hi,

I have the following very simple test case, but I can't get the keymap working when I press a or b or c in the document.

Is it currently broken or I did something stupid?

Thanks.



<html>
<head>
<script type="text/javascript" src="lib/ext/yui-utilities.js"></script>
<script type="text/javascript" src="lib/ext/ext-yui-adapter.js"></script>
<script type="text/javascript" src="lib/ext/ext-all.js"></script>
<script type="text/javascript">
Ext.EventManager.onDocumentReady(function() {
    var map = new Ext.KeyMap('container',[{
        key : "abc",
        fn : function() {alert('a, b or c was pressed');}
    }]);
}, null, true);
</script>
</head>
<body>
<div id="container">
    

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna. Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit. Quisque dolor magna, ornare sed, elementum porta, luctus in, leo.</p>
</div>
</body>
</html>
Reply With Quote
  #2  
Old 03-06-2007, 06:02 AM
Default

I am assuming keys are not being routed to "container" because it doesn't have any element in it which can have the focus to receive keystrokes.
Reply With Quote
  #3  
Old 03-06-2007, 05:11 PM
Default

Hi Jack,

Thanks for your reply. You're absolutely right.

Somehow the way EXT mimic traditional GUI framework makes me think that I can attach keymap to any objects :-) My bad.

What I was trying to do is to create some "global" shortcut key that will trigger some javascript callback. So it looks like the user must focus on some html elements that can generate key events for it to work.

My workaround is to use the accesskey attributes and bind them to some offscreen <a> tags. It restricts the global hotkey to have a alt modifier but I can live with that.

I'm using this shortcut to toggle the expand / collapse of the side panels.

I notice that currently LayoutRegion does not export the
collapsed
field which I use to for the toggle function.

It's not a big deal because I usually go directly to the source code for info, but for someone that mainly lookup the online doc they might miss this.

Anyway, thanks for your great work!


            function toggleRegionShowCollapse() {
                if (this.collapsed) {
                    this.expand();
                } else {
                    this.collapse();
                }
            }
Reply With Quote
  #4  
Old 03-06-2007, 07:26 PM
Default

Any chance we can alternately bind the keynav to the document so we can have app-wide keynav handlers?
Reply With Quote
  #5  
Old 03-07-2007, 07:59 AM
Default

I did this and everything seems to work fine.
            var documentKeyMap = new Ext.KeyMap(document, [
			    {
			        key: "q",
			        ctrl: true,
			        fn: this.showSearchDialog
			    }
			]);
Reply With Quote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值