我在我的项目中使用了这种方式:
Screen screen = new Screen();
screen.click(<your texbox>); // click into textbox to have a cursor there
screen.type("a", KeyModifier.CTRL); // this sends Ctrl+"a" to select all text <- this is what you asked for !
screen.type(Key.BACKSPACE); // this sends Backspace key pressed, i.e. here deletes all selected text
请注意,我同时使用了 KeyModifier 和 Key。这样就成功了。
试试这个,
Screen screen = new Screen();
screen.type("x",Key.CTRL)
screen.type("\n");
使用KeyEvent中的按键代码:
DesktopKeyboard keyboard = new DesktopKeyboard();
keyboard.keyDown(KeyEvent.VK_CONTROL);
keyboard.type("x");
keyboard.keyUp(KeyEvent.VK_CONTROL);
我写了一个 typeChaine 函数:
def typeChaine(chr):
# print (msg.format(chr))
for car in chr:
# print(car)
keyDown(Key.ALT)
type(Key.NUM0)
for num in str(ord(car)):
#type(Key.NUMnum)
print(num)
if (num == "0"):
type(Key.NUM0)
elif (num == "1"):
type(Key.NUM1)
elif (num == "2"):
type(Key.NUM2)
elif (num == "3"):
type(Key.NUM3)
elif (num == "4"):
type(Key.NUM4)
elif (num == "5"):
type(Key.NUM5)
elif (num == "6"):
type(Key.NUM6)
elif (num == "7"):
type(Key.NUM7)
elif (num == "8"):
type(Key.NUM8)
elif (num == "9"):
type(Key.NUM9)
keyUp(Key.ALT)