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
- #BACKSPACE /
-
- #TAB
-
- #ENTER /
#RETURN
- #ENTER /
-
- #INS /
#INSERT
- #INS /
-
- #PRTSC
-
- #CAPS_LOCK
-
- #F1
-
- #F2
-
- #F3
-
- #F4
-
- #F5
-
- #F6
-
- #F7
-
- #F8
-
- #F9
-
- #F10
-
- #F11
-
- #F12
-
- #PLAY /
#PAUSE /
#PLAY_PAUSE
- #PLAY /
-
- #NEXT
-
- #PREV /
#PREVIOUS
- #PREV /
-
- #STOP
-
- #MUTE
-
- #VOL_UP /
#VOLUME_UP
- #VOL_UP /
-
- #VOL_DOWN /
#VOLUME_DOWN
- #VOL_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