如何在 Javascript/Php 中创建全局键盘快捷键?
我正在尝试以 ajax+php 的方式创建一种管理应用程序。我对 JS 和 PHP 编码有点陌生,所以我认为这将是一个很好的测试,它是那些可能没有用的东西之一,你编写它来搞砸。
由于该应用程序要在打开另一个窗口的情况下使用,因此我需要创建一个键盘快捷键,无论哪个窗口处于焦点状态,该快捷键都可以使用。有什么方法可以在 Php/Javascript 中做到这一点吗?
I'm attempting to create a sort of management application in an ajax+php sort of fashion. I'm sort of new to coding JS and PHP, so I figured that this would be a nice test, it's one of those things that may not have a use and you code it to screw around.
Since the application is to be used with another window open, I need to create a keyboard shortcut that will work regardless of which window is in focus. Is there any way to do that in Php/Javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 是一种服务器端语言,因此它根本无法做这样的事情。它无法接收点击、按键等用户事件。Javascript
在客户端的浏览器中运行,可以处理用户事件,但只能处理源自当前窗口的事件。
抱歉,您需要找到不同的解决方案。我敢打赌 http://www.superuser.com 上有很多很好的问题和答案,可以帮助您你
PHP is a server-side language, so it won't be able to anything like this at all. It can't receive user events like clicks, keypresses, etc.
Javascript runs in the browser on the client side and can handle user events, but only ones which originate from the current window.
You'd need to find a different solution, sorry. I would bet that there's a lot of good questions and answers on http://www.superuser.com which could help you
这在基于浏览器的 Web 应用程序中根本不可能实现。仅当浏览器窗口聚焦时,甚至当您的特定选项卡聚焦时,您才能对击键做出反应。这是网络浏览器的安全沙箱功能。想想如果一个网站被最小化并将您的所有击键记录到您正在输入的所有其他窗口中会发生什么...银行密码...等等...抱歉!
This is simply not possible in browser based web applications. You can only react to keystrokes when the browser window is focused, and even then, when your specific tab is focused. This is a security sandbox feature of web browsers. Think about what would happen if a website was minimized and logged all your keystrokes to all other windows you were typing in... bank passwords... etc.... Sorry!