我们可以使用WebSocket发送远程密钥事件吗?

我们可以使用WebSocket发送远程密钥事件吗?,websocket,socket.io,Websocket,Socket.io,我可以使用WebSocket模拟跨浏览器的键盘吗。 我希望模拟箭头键和F11。键事件在浏览器中已经存在很多年了 看 要获得支持列表 在jQuery中处理关键事件 Websockets是一种较新的技术,并非所有浏览器都提供这种技术,但如果需要,您可以在旧浏览器(如Socket.io)上使用模拟web套接字的库来执行双向实时消息传递 客户端上的伪代码如下所示: (function ($) { function simulateKeyPress(character) { jQue

我可以使用WebSocket模拟跨浏览器的键盘吗。
我希望模拟箭头键和F11。

键事件在浏览器中已经存在很多年了

看 要获得支持列表

在jQuery中处理关键事件

Websockets是一种较新的技术,并非所有浏览器都提供这种技术,但如果需要,您可以在旧浏览器(如Socket.io)上使用模拟web套接字的库来执行双向实时消息传递

客户端上的伪代码如下所示:

(function ($) {
    function simulateKeyPress(character) {
      jQuery.event.trigger({ type : 'keypress', which : character.charCodeAt(0) });
    }

    function onkeypress(key, ts) {
       var act = {"timestamp" : ts, "key" : key};
       socketIoClient.emit("message", act);
    }

    $('body').keypress(function(e) {
       // Send date in case you want to order/buffer on the server
      onkeypress(e.which, new Date());
    });

    var socketIoClient = io.connect(null, {
       'port': '#socketIoPort#'
        , 'rememberTransport': true
        , 'transports': ['websocket', 'xhr-polling'] // put here all the transports you need
    });

    // Handle the key press events
    socketIoClient.on('message', function(json) {
      var act = JSON.parse(json);
      if (act) {
      // Not sure what the keys will do but if you just want to echo them
       simulateKeyPress(act.key);
     }
    });
})(jQuery);

希望这有帮助

浏览器中的关键事件已经存在多年了

看 要获得支持列表

在jQuery中处理关键事件

Websockets是一种较新的技术,并非所有浏览器都提供这种技术,但如果需要,您可以在旧浏览器(如Socket.io)上使用模拟web套接字的库来执行双向实时消息传递

客户端上的伪代码如下所示:

(function ($) {
    function simulateKeyPress(character) {
      jQuery.event.trigger({ type : 'keypress', which : character.charCodeAt(0) });
    }

    function onkeypress(key, ts) {
       var act = {"timestamp" : ts, "key" : key};
       socketIoClient.emit("message", act);
    }

    $('body').keypress(function(e) {
       // Send date in case you want to order/buffer on the server
      onkeypress(e.which, new Date());
    });

    var socketIoClient = io.connect(null, {
       'port': '#socketIoPort#'
        , 'rememberTransport': true
        , 'transports': ['websocket', 'xhr-polling'] // put here all the transports you need
    });

    // Handle the key press events
    socketIoClient.on('message', function(json) {
      var act = JSON.parse(json);
      if (act) {
      // Not sure what the keys will do but if you just want to echo them
       simulateKeyPress(act.key);
     }
    });
})(jQuery);
希望这对你有所帮助当然你可以

打开到Websocket服务器的连接,并在每次jQuery keyUp事件时向其发送请求! 在websocket端,只需将事件抛出传递给其他浏览器连接。 在另一个浏览器上,只需模拟按键SimulateKeyPress; 你当然可以

打开到Websocket服务器的连接,并在每次jQuery keyUp事件时向其发送请求! 在websocket端,只需将事件抛出传递给其他浏览器连接。 在另一个浏览器上,只需模拟按键SimulateKeyPress;
做什么?你试过什么?我的网页里有一个iframe。这个iframe元素,谷歌演示可以使用键盘控制。但是因为我想从远程浏览器发送事件,所以我想模拟关键事件。谢谢你做什么?你试过什么?我的网页里有一个iframe。这个iframe元素,谷歌演示可以使用键盘控制。但是因为我想从远程浏览器发送事件,所以我想模拟关键事件。谢谢