# Have Robot type any arbitrary message via keyboard in vision?

**URL:** <https://forum.inductiveautomation.com/t/have-robot-type-any-arbitrary-message-via-keyboard-in-vision/47190>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [May 27, 2021, 2:36pm UTC](https://forum.inductiveautomation.com/t/have-robot-type-any-arbitrary-message-via-keyboard-in-vision/47190 "2021-05-27T14:36:08Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 27, 2021, 5:01pm UTC](https://forum.inductiveautomation.com/t/have-robot-type-any-arbitrary-message-via-keyboard-in-vision/47190/14 "2021-05-27T17:01:44Z")

</div>

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.

```auto
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()

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/have-robot-type-any-arbitrary-message-via-keyboard-in-vision/47190)._
