mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 12:58:36 -07:00
add delay
This commit is contained in:
@@ -400,24 +400,30 @@ static void js_badusb_println(struct mjs* mjs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Simulates typing a character using the ALT key and Numpad ASCII code
|
// Simulates typing a character using the ALT key and Numpad ASCII code
|
||||||
static void alt_numpad_type_character(char character) {
|
static void alt_numpad_type_character(struct mjs* mjs, char character) {
|
||||||
|
const uint32_t delay_ms = 50; // Example delay
|
||||||
|
|
||||||
// Press and hold the ALT key
|
// Press and hold the ALT key
|
||||||
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
|
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
|
||||||
|
js_delay_with_flags(mjs, delay_ms);
|
||||||
|
|
||||||
// Convert the character to its ASCII value and then to a string
|
// Convert the character to its ASCII value and then to a string
|
||||||
char ascii_str[4];
|
char ascii_str[4];
|
||||||
snprintf(ascii_str, sizeof(ascii_str), "%03d", character);
|
snprintf(ascii_str, sizeof(ascii_str), "%03d", character);
|
||||||
|
|
||||||
// For each digit in the ASCII string, create a temp string and press/release the corresponding numpad key
|
// For each digit in the ASCII string, press and release the corresponding numpad key
|
||||||
for(size_t i = 0; ascii_str[i] != '\0'; i++) {
|
for(size_t i = 0; ascii_str[i] != '\0'; i++) {
|
||||||
char temp_str[2] = {ascii_str[i], '\0'}; // Create a temporary string for each digit
|
char digitStr[2] = {ascii_str[i], '\0'};
|
||||||
uint16_t numpad_keycode = get_keycode_by_name(temp_str, 1);
|
uint16_t numpad_keycode = get_keycode_by_name(digitStr, 1);
|
||||||
furi_hal_hid_kb_press(numpad_keycode);
|
furi_hal_hid_kb_press(numpad_keycode);
|
||||||
|
js_delay_with_flags(mjs, delay_ms);
|
||||||
furi_hal_hid_kb_release(numpad_keycode);
|
furi_hal_hid_kb_release(numpad_keycode);
|
||||||
|
js_delay_with_flags(mjs, delay_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the ALT key
|
// Release the ALT key
|
||||||
furi_hal_hid_kb_release(KEY_MOD_LEFT_ALT);
|
furi_hal_hid_kb_release(KEY_MOD_LEFT_ALT);
|
||||||
|
js_delay_with_flags(mjs, delay_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void js_badusb_altPrintln(struct mjs* mjs) {
|
static void js_badusb_altPrintln(struct mjs* mjs) {
|
||||||
@@ -431,7 +437,7 @@ static void js_badusb_altPrintln(struct mjs* mjs) {
|
|||||||
size_t text_len;
|
size_t text_len;
|
||||||
const char* text = mjs_get_string(mjs, &obj_string, &text_len);
|
const char* text = mjs_get_string(mjs, &obj_string, &text_len);
|
||||||
for (size_t i = 0; i < text_len; ++i) {
|
for (size_t i = 0; i < text_len; ++i) {
|
||||||
alt_numpad_type_character(text[i]);
|
alt_numpad_type_character(mjs, text[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate pressing the ENTER key at the end
|
// Simulate pressing the ENTER key at the end
|
||||||
|
|||||||
Reference in New Issue
Block a user