douman6245 2014-08-14 05:59
浏览 20

在PHP或AJAX中读取键击

I would like to get my page to read keystrokes wherever the person is focused on the website.

So like if they had the web page open and they pressed <kbd>1</kbd> then it did something and if they pressed <kbd>2</kbd> it did something else and so on. I don't mean to do this in an input tag.

How would I go about doing this? Can PHP just catch the keystroke and do something or does it have to respond back with AJAX? If so, how?

  • 写回答

1条回答 默认 最新

  • dpe77294 2014-08-14 06:03
    关注

    You'll need to listen to a keyboard event with JavaScript.

    PHP is a server side language and cannot help you for this.

    Simple demo over here: http://jsbin.com/lamow/1/edit

    document.addEventListener('keypress', function(event) {
      console.log(arguments);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM