var ws = new WebSocket("ws://213.27.32.135:8100"); ws.onmessage = function(event) { Как здесь нажать клавишу "Z"? } 
  • why exactly Z? Why not just make DEBUG_FLAG and rely on it when testing? - Alexey Shimansky
  • I'm just starting to work with JS and I don’t know what it is DEBUG_FLAG, and I need Z to press a button in my flash clip - ArtGrek13
  • DEBUG_FLAG is its own variable that takes true / false value ...... when true means it is pressed, when false it is not pressed - Alexey Shimansky
  • and how to combine it with my task? I have a "auto" button in the flash, which the client can click with the mouse or from the "Z" keyboard. I need to use the command from the server, the "auto" mode is turned off, to do this, press "Z" - ArtGrek13
  • I have no idea how you implement it yourself ... as you manipulate the keys there .. but you write Как имитировать нажатие клавиши - I wrote you - Alexey Shimansky

1 answer 1

imitates this way, the alert shows when you click on Z and the onmessage event

 var e = jQuery.Event( "keypress", { which: 122 } ); window.onkeypress = function(event) { if(event.which == 122){alert("ok")} } var ws = new WebSocket("ws://213.27.32.135:8100"); ws.onmessage = function(event) { КакjQuery( здесь"body" нажать).trigger( клавишуe "Z"?); } 

Can anyone tell me why the flash does not respond to such a click?

  • Flash itself, why should it respond to jQuery with which it is not connected? - Grundy
  • when i click on the keyboard Z, the button in the flash is pressed, when i imitate the click in javascript is not the same click? - ArtGrek13
  • No, not the same. - Grundy
  • and how to do the same? - ArtGrek13
  • In general, no way. And this is good, since it allows to distinguish a program event from an event from a real keyboard. In the case of a flash drive, if it is yours, then you need to pull out the function that is performed by pressing Z and call it directly from js, without any trigger. If there is no access to the flash drive code, then, most likely, there is no way. - Grundy