Screenshots with Digispark at the touch of a button

Hello everyone

in today's post I would like to briefly show how easy our Digispark can be used as an additional button for creating screenshots. We have already started using it as a USB device in a previous post Shown. The reason for this article was the request of a customer, who wanted to take screenshots during the video game with the help of a foot button.

We need:

The wiring is simple:

 

The DigiKeyboard.h library allows you to simulate a key press with the Digispark. In order to really simulate all the keys, we need the Buttons IDs. These can be found at the following link:

https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf

On page 53, Table 12 lists the IDs for keyboard keys:

The entry with ID 70 is associated with the print key on the keyboard:

 

Here is the code:

 

#include "DigiKeyboard.h"
#define KEY_PRINT 70 here the USB key ID is assigned.
#define KEY_PRINT 0x46 <- can also be specified in Hex.
#define MOD_GUI_LEFT 227 or 0xE3

Void Setup() {   pinMode(2,INPUT_PULLUP); Button for input to Pin2
}

Void Loop() {   Int Button = digitalRead(2);   If (Button == 0){     DigiKeyboard.sendKeyStroke(KEY_PRINT, MOD_GUI_LEFT);
DigiKeyboard.Delay(1000); de-bouncing
}
 DigiKeyboard.Delay(100);
}

If the button is now pressed, a screenshot is stored in sequential numbering in the profile directory Pictures -> Screenshots.

On this basis, it is easy to modify the Sketch to mute the sound of a PC, for example, when a door with a contact switch is opened or closed.

Have fun re-crafting & until the next time

Projekte für anfänger

1 comment

Tobias Kuch

Tobias Kuch

Anmerkung zur Funktion des Codes:

Es wird mit dem gelisteten Code , nicht wie beschrieben, EIN Screenshot bei Betätigung des Tasters abgelegt, sondern es werden, solange der Taster bestätigt (gedrückt) ist, alle 100ms ein Screenshot (in fortlaufender Nummerierung ) erstellt.

Leave a comment

All comments are moderated before being published