Have Robot type any arbitrary message via keyboard in vision?

I wonder if something like this would work? You’ll have to invoke loginAsMe from an async thread - EventQueue will throw if you try to call invokeAndWait from the EDT.

from java.awt import EventQueue

DELAY_FACTOR = 200

WINDOW_SELECT_PIXELS = {
	"Privileged Access": (1300, 1050),
	"Overview": (500, 1050),
	"Print Screen": (1900,1050),
	"Login": (1400,40)
}

def __invokeBlocking(fn, *args):
	EventQueue.invokeAndWait(lambda: fn(*args))

def __pressKey(keyCode):
	rob.keyPress(keyCode)
	rob.keyRelease(keyCode)

def goToWindow(window, initial_delay=0):
	"""
	Goes to a specific window via bottom navigation.
	Args:
		window: str, which window do you want to go to?
	Returns:
		None, moves mouse and clicks button, or throws KeyError if bad window name
	"""
	x, y = WINDOW_SELECT_PIXELS[window]
	__invokeBlocking(leftClick, x, y)

def pressTab():
	__invokeBlocking(__pressKey, KeyEvent.VK_TAB)

def pressEnter():
	__invokeBlocking(__pressKey, KeyEvent.VK_ENTER)

def type_on_keyboard(message, initial_delay=0):
	"""
	message: str, the key strokes you want simulated
	initial_delay: int, - for the first thing you type in, but probably otherwise.  needed for chaining
	"""
	str_message = String(message)
	for keyCode in (KeyEvent.getExtendedKeyCodeForChar(k) for k in str_message.chars().iterator()):
		__invokeBlocking(__pressKey, keyCode)
	
def moveMouse(x, y):
	"""
	Call leftClick at a specified pixel.
	"""
	__invokeBlocking(rob.mouseMove, x, y)

def loginAsMe():
	goToWindow("Login")
	type_on_keyboard("secretusername") 
	pressTab() 
	type_on_keyboard("secretpassword")
	pressEnter()
1 Like