⌚SB Watch 2
🚚 Free fedex shipping from 97 $
🌎 WORLDWIDE SHIPPING for 25 $
Search
Close this search box.

Bluetooth Keyboard

About

MagiScript can turn a compatible device like the Atom into a Bluetooth keyboard. This enables the device to send keystrokes to a phone or computer that has been paired with it.

To use the keyboard and media support in MagiScript, you need to pair your device with the target phone or computer. Once the pairing process is complete, you can use the available functions to send keystrokes or media commands to the target device.

When Atom is paired with a phone, it automatically connects to Atom when turned on. You can still connect to Atom via Bluetooth from the same host device to develop mini-apps or use Atom. You can even pair another device, but this can start being unreliable. If you experience that you cannot connect to Atom again, or your device cannot pair with it, go to your Bluetooth settings to unpair Atom, and connect to it again.

Keyboard Type

The keyboard.type() function allows you to type a string of characters on the target device. The function takes a string as its argument, and it types each character of the string sequentially. For example, if you want to type the string “Hello, world!”, you can use the following code:

				
					keyboard.type('Hello, world!');
				
			

You can use multiple values, and even numbers. Atom will add a space between them:

				
					keyboard.type('Hello', 'World');
keyboard.type('Temperature:', 42);
				
			

Keyboard Tap

The keyboard.tap() function allows you to tap a specific key on the target device. The function takes a keyCode as its argument, which represents the key that you want to tap. The available keyCodes are listed below:

    • KBD_UP

    • KBD_DOWN

    • KBD_LEFT

    • KBD_RIGHT

    • KBD_PAGE_UP

    • KBD_PAGE_DOWN

    • KBD_HOME

    • KBD_END

    • KBD_BACKSPACE

    • KBD_TAB

    • KBD_RETURN

    • KBD_ESC

    • KBD_INSERT

    • KBD_PRTSC

    • KBD_DELETE

    • KBD_CAPS_LOCK

    • KBD_F1

    • KBD_F2

    • KBD_F3

    • KBD_F4

    • KBD_F5

    • KBD_F6

    • KBD_F7

    • KBD_F8

    • KBD_F9

    • KBD_F10

    • KBD_F11

    • KBD_F12

For example, if you want to tap the “Enter” key, you can use the following code:

				
					keyboard.tap(KBD_RETURN);
				
			

Also, multiple keys can be listed:

				
					keyboard.tap(KBD_UP, KBD_END);
				
			

Media Key Tap

The media.tap() function allows you to send media commands to the target device. The function takes a mediaKeyCode as its argument, which represents the media command that you want to send. The available mediaKeyCodes are listed below:

    • MEDIA_PLAY_PAUSE

    • MEDIA_NEXT_TRACK

    • MEDIA_PREVIOUS_TRACK

    • MEDIA_STOP

    • MEDIA_VOLUME_UP

    • MEDIA_VOLUME_DOWN

    • MEDIA_MUTE

For example, if you want to play or pause media playback on the target device, you can use the following code:

				
					media.tap(MEDIA_PLAY_PAUSE);
				
			

Keyboard Send

The keyboard.send() command serves as the foundation for all other keyboard-related functions. For instance, the Custom Keyboard built-in application utilizes this command to transmit key presses. This allows users to configure the function and media keys in the settings (as strings).

When you pass a simple string, it will act as keyboard.type(). You can use keywords, it will act as a keyboard tap or media key tap.

There are two special keywords, their behaviour can be configure in the settings:

    • #SEPARATOR

    • #SUBMIT (usually an ENTER)

And the available keywords are:

    • #UP

    • #DOWN

    • #LEFT

    • #RIGHT

    • #PAGE_UP

    • #PAGE_DOWN

    • #HOME

    • #END

    • #BACKSPACE /
      #DEL /
      #DELETE

    • #TAB

    • #ENTER /
      #RETURN

    • #INS /
      #INSERT

    • #PRTSC

    • #CAPS_LOCK

    • #F1

    • #F2

    • #F3

    • #F4

    • #F5

    • #F6

    • #F7

    • #F8

    • #F9

    • #F10

    • #F11

    • #F12

    • #PLAY /
      #PAUSE /
      #PLAY_PAUSE

    • #NEXT

    • #PREV /
      #PREVIOUS

    • #STOP

    • #MUTE

    • #VOL_UP /
      #VOLUME_UP

    • #VOL_DOWN /
      #VOLUME_DOWN

For example:

				
					keyboard.send('Hello', '#SEPARATOR', 'World', '#ENTER', '#PLAY');
				
			

Note

It’s important to note that not all devices support all keyCodes and mediaKeyCodes. Also, some devices may have additional keyCodes or mediaKeyCodes not listed here.

Conclusion

MagiScript provides a simple and convenient way to turn a compatible device into a Bluetooth keyboard and send keystrokes or media commands to a target device. With the available functions, developers can create various applications that require keyboard or media input.

General

πŸ“ƒΒ First Steps

MagiScript Editor

πŸ“ƒΒ Basics

πŸ“ƒΒ Running Your First Program

πŸ“ƒΒ App Store

πŸ“ƒΒ Atom Settings (Editor)

πŸ“ƒΒ Debugging Techniques

Examples

πŸ“ƒΒ Atom Time

🎞️ Time Practice

πŸ“ƒΒ Atom Pi (Pi Revelations)

πŸ“ƒΒ Atom Drum

🎞️ Atom Stack

πŸ“ƒΒ Atom Square

πŸ“ƒΒ Atom Level

πŸ“ƒΒ Atom THMPR

πŸ“ƒΒ Poker Hands

πŸ“ƒΒ Keyboard Numeric

πŸ“ƒΒ Keyboard NOKIA

πŸ“ƒΒ Keyboard Cursor

πŸ“ƒΒ Keyboard Media

πŸ“ƒΒ Keyboard Custom

Input/Output

πŸ“ƒΒ Buttons

πŸ“ƒΒ Vibration Motor

πŸ“ƒΒ RGB LED

πŸ“ƒΒ Devices

πŸ“ƒΒ PeekSmith

πŸ“ƒΒ SB Watch

πŸ“ƒΒ Bluetooth Keyboard

πŸ“ƒΒ Bluetooth Mouse

πŸ“ƒΒ Timers

πŸ“ƒΒ Database

πŸ“ƒΒ Events

πŸ“ƒΒ System (exit, sleep, rand)

πŸ“ƒΒ Objects (card, time)

Language

πŸ“ƒΒ Summary

πŸ“ƒΒ Comments

πŸ“ƒΒ Variable Declarations

πŸ“ƒΒ Operators

πŸ“ƒΒ Control Flow

πŸ“ƒΒ Functions

πŸ“ƒΒ Numbers

πŸ“ƒΒ Strings

πŸ“ƒΒ Arrays

πŸ“ƒΒ Objects

πŸ“ƒΒ Uint8Array