【问题标题】:HTML button to activate keyboard simulation用于激活键盘模拟的 HTML 按钮
【发布时间】:2018-03-16 14:18:12
【问题描述】:

我想在 Internet Explorer 的 HTML 中制作 3 个按钮来激活模拟按键“Alt+o”、“Alt+w”和“Alt+c”。

解释我想做什么- 我制作了一个处理各种事情的网站,现在正在尝试激活后台程序。我已经安装了 AutoHotKey,我可以让这些按钮与键盘一起使用,但我想在没有连接键盘的情况下运行它。

我在这里找到了 2 个其他类似的回复,但我无法让它们工作,因为它们是较旧的线程,我想我会开始一个新线程来看看那里有什么。

编辑:我不想按 Alt+o 键来触发某些东西(我已经有了),我想要相反的,一个触发(模拟)Alt+o 组合键的按钮

【问题讨论】:

标签: javascript html internet-explorer autohotkey


【解决方案1】:

你可以这样做。

  $('<selector element>').keydown(function(e){
       var arrayOfCharcode=[111,99,119];//ascii codes need to be allowed
       if(e.altKey && arrayOfCharcode.indexOf(e.which)>=0){
          e.preventDefault();
           prompt("Alt+<charcode ascii>, Enter","text");
       }
   });

你可以这样做

$(document).keydown(function(e){
       var arrayOfCharcode=[99,111,119,68,79,87];//ascii codes need to be allowed
       if(e.altKey && arrayOfCharcode.indexOf(e.which)>=0){
          e.preventDefault();
          switch(e.which){
              case 99:
              case 68:
                    //call button1 function  alt + c
                break;
            case 111:
            case 79:
                    //call button2 function alt + o
                break;
            case 119:
            case 87:
                    //call button3 function alt +w
                break;
          }
       }
   });

【讨论】:

  • 感谢您的快速回复。每个按钮一次只需要 1 个组合。我猜这会连续 3 次。更具体地说,我在后台运行一个灯光程序,并希望 Alt+o 关闭灯光(我可以用键盘和顶部的网页来做到这一点)其他 2 个操作不同的灯光功能。是否要修改第一部分 - $('') 以链接到按钮(例如 $('button1')?提示行是什么?
  • 编辑:我不想按 Alt+o 键来触发某些东西,我想要相反的东西,触发 Alt+o 组合键的东西
猜你喜欢
  • 2012-09-21
  • 2015-03-27
  • 2021-08-29
  • 2011-09-17
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多