[英]How to send key press input into a browser via code (e.g. java)
I plan on writing a solver to the recently popular 2048 game 我打算为最近流行的2048游戏写一个求解器
I'm wondering how I could go about this without actually building the game first then solving it... My question is: Is there a way I can send key presses (eg 'left' 'right' 'up' and 'down' ) into a web-browser via some sort of language like java/c? 我想知道如何在没有实际建立游戏然后解决它的情况下解决这个问题...我的问题是:有没有办法可以发送按键(例如'左''右''上'和'下' )通过某种语言如java / c进入Web浏览器?
Sorry if this question has been posted before, I was not sure how to actually phrase the question and could not find any results. 很抱歉,如果此问题之前已发布,我不确定如何实际说出问题,但找不到任何结果。
use keybd_event function to send key press, example : 使用keybd_event函数发送按键,例如:
keybd_event(VK_UP,0xE0,0,0);//do click, it will be stay pressed until you release it
keybd_event(VK_UP,0xE0,KEYEVENTF_KEYUP,0);//release click
the second parameter is scan code,there is a list of make and break scan codes for each key http://stanislavs.org/helppc/make_codes.html , and here you can find the virtual key codes http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx 第二个参数是扫描码,每个键http://stanislavs.org/helppc/make_codes.html都有一个make和break扫描码列表,在这里你可以找到虚拟键码http://msdn.microsoft .COM / EN-US /库/窗/桌面/ dd375731(v = vs.85)的.aspx
Using Java applets you can add a text listener to your component and capture the Keystrokes. 使用Java applet,您可以向组件添加文本侦听器并捕获Keystrokes。 For example, in the code below you are capturing the keystrokes of a textbox.
例如,在下面的代码中,您捕获文本框的击键。
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
public class KeyReader extends Applet{
private static final long serialVersionUID = 1L;
public void init(){
TextField textBox = new TextField(" ");
add(textBox);
textBox.addKeyListener (new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
System.out.println("You Pressed " + keyCode);
}
}
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.