nativeType

nativeType(keys)

This function simulates user keyboard input using the operating system's facilities, sending keypresses to the currently active window, i.e., to the window with keyboard focus. On Windows, this can be used to interact with native Windows message boxes, for example. The keyboard input will be sent to whatever widget has the keyboard focus. The input is case-sensitive, so nativeType("R") is different from nativeType("r").

This function can also simulate the input of special keys by using their names and enclosing them in angle brackets (<>), and can simulate combinations of keys by separating each key name with a +. Here are some examples:

nativeType("Hello");
nativeType("<Return>");
nativeType("<Alt+F4>");
nativeType("<Alt+Tab>");
nativeType("<Ctrl+c>");

This is valid in JavaScript, Perl, Python, and Ruby.

invoke nativeType "Hello"
invoke nativeType "<Return>"
invoke nativeType "<Alt+F4>"
invoke nativeType "<Alt+Tab>"
invoke nativeType "<Ctrl+c>"

The nativeType function can accept all the normal alphanumeric characters (which are written literally), as well as the following special keys (which must be enclosed in angle brackets): <Alt>, <Ctrl>, <Shift>, <Escape>, <Return>, <Space>, <Backspace>, <Tab>, <Pause>, <PageUp>, <PageDown>, <Home>, <End>, <Left>, <Right>, <Up>, <Down>, <Insert>, <Delete>, <Print>, <NumPad0>, <NumPad1>, <NumPad2>, <NumPad3>, <NumPad4>, <NumPad5>, <NumPad6>, <NumPad7>, <NumPad8>, <NumPad9>, <NumPadMultiply>, <NumPadAdd>, <NumPadSubtract>, <NumPadDivide>, <NumPadDecimal>, <MenuLeft>, <MenuRight>, <Win>, <WinLeft>, <WinRight>, <F1>, <F2>, <F3>, <F4>, <F5>, <F6>, <F7>, <F8>, <F9>, <F10>, <F11>, <F12>, <F13>, <F14>, <F15>, <F16>, <F17>, <F18>, <F19>, <F20>, <F21>, <F22>, <F23>, <F24>, <NumLock>, <ScrollLock>, <CapsLock> and <Command> (macOS only) .

It is usually better to use one of the toolkit-specific type(objectOrName, text) functions.

Note: In theory it is possible for keypresses entered with the nativeType function to go astray. For example, if a window unexpectedly pops up over the AUT, the keypresses will go to the newly active window rather than to the intended one. In practice this is a very rare occurrence.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.