How to print tabs?

\t tabs are not printing. Interesting that the new lines print using similar notation \n.
Is there a trick to printing tabs?

#include <Keyboard.h>

void setup()

void loop()
	Keyboard.print("\ntab>>\t\t<<tab\n"); // tab does not print

	while(true) { } 



Could be from this:

Note: Not every possible ASCII character, particularly the non-printing ones, can be sent with the Keyboard library. The library supports the use of modifier keys. Modifier keys change the behavior of another key when pressed simultaneously. See here for additional information on supported keys and their use.


That links here: Arduino - KeyboardModifiers

There's a constant defined for KEY_TAB there. Might check into that. (I lack the requisite hardware to look into this myself.)

Thank you SirNickity. This work around prints a tab:; 

The Keyboard.write() and and Keyboard.release() commands don’t work with every possible ASCII character, only those that correspond to a key on the keyboard.

-- Arduino - KeyboardModifiers

Tab is a printable character, and it is on the keyboard. Some of the old ASCII characters are obsolete and do not appear on the keyboard.

This work around prints a tab:

Workaround? I don't understand why you considering using the proper method for printing a tab to be a workaround. The \t pair of characters requires some intelligence to process, such as that built into a compiler. Try typing \t into your word processor application, and see it it interprets the pair of characters as a tab.

The \t pair of characters requires some intelligence to process

That’s a valid point.

But the print() function doesn’t print literal tabs:

Keyboard.print("tab>>		<<tab"); // does not print literal tabs



But the print() function doesn’t print literal tabs:

Because a tab, per-se, is not a printable character. It is s directive to an application to reposition the cursor some number of spaces to the right. The application needs to determine the number of spaces.

Thank you for the explanation PaulS. :slight_smile:

Tab is indeed a non-printable character, it is number 9 in the ASCII control character chart.

Of course, we're not really "printing" a tab here, we're generating a keypress event for the tab key.
IMO, "keyboard.print('\t')" really ought to know how to send a tab. For some reason the ascii translation table (_asciimap in HID.cpp) has an entry for Tab that is NOT the same value as KEY_TAB. (hmm. Also true for backspace and newline...)
This may have something to do with varying keyboards. (Hmm. According to documentation I can find, the current value in _asciimap is correct, and KEY_TAB is not documented anywhere as being a tab...)