Package: sendevent-getevent-keyboard
ADB sendevent - press multiple keys at the same time, control the duration of each event!Take a look at the video to see what the code below does:https://www.youtube.com/watch?v=GO2XsvI6TZk$pipinstallsendevent-getevent-keyboardfromtimeimportsleepfromsendevent_getevent_keyboardimportSendEventKeystrokessendeventkey=SendEventKeystrokes(adb_path="C:\\Users\\Gamer\\AppData\\Local\\Android\\Sdk\\platform-tools\\adb.exe",deviceserial="localhost:5735",sdcard="/storage/emulated/0/",# it is probably better to pass the path than the symlinktmp_folder_on_sd_card="AUTOMAT",# The folder will be created if it doesn't exist. All temp files will be stored thereexit_keys="ctrl+x",# If you want to interrupt adb)sendeventkey.connect_to_adb()sleep(3)# KEY_LEFTSHIFT + KEY_1 will result in "!" / Pass as many keys as you want. You can see a complete list by calling:# SendEventKeystrokes.show_all_letter_codes() Keys on the left will get some additional execution time.sendeventkey.press_multiple_keys_at_the_same_time(keylist=["KEY_LEFTSHIFT","KEY_1"],time_to_press=0.5)# For the method SendEventKeystrokes.write_text() only these keys are available:# https://android.googlesource.com/platform/external/kernel-headers/+/8bc979c0f7b0b30b579b38712a091e7d2037c77e/original/uapi/linux/input.h# If there are special characters, like ä/ö/ü, they will be normalized before sending the keystrokes. (ä - a / ü - u / ö - o)# Characters will be sent as lower case. Using this method, you cannot send upper case letters.sendeventkey.write_text(textlist=["Hi my friend, how are you","ENTER"],speed=4,# used for the chunk calculation (or how many sendevents are passed at the time)nosleep=False,# if False, there will be no sleep between sending the letter chunksadd_to_sleep_time=(0.01,0.05),# random sleep range)sleep(3)sendeventkey.press_key_for_certain_time(("a",2),("b",1),("c",1),("d",0))# pass as many tuples as you want, you can see all available keys by calling SendEventKeystrokes.show_all_letter_codes()sleep(3)# If you want to repeat the same action over and over again, create a DataFrame, this will save a little bit of time for future executionsdf=sendeventkey.get_keystrokes_df_for_text(textlist=["text to reuse","right","ENTER"],speed=4,# "right" and "ENTER" are not interpreted as text, but as control keys)# Execute the keystrokes By the way: if nosleep is True, add_to_sleep_time will be ignoredsendeventkey.write_text_df(df,nosleep=True,add_to_sleep_time=(1,2))"""sendeventkey.show_all_letter_codes()0                   1                     2                     3                  40            ABS_BRAKE             ABS_GAS             ABS_HAT0X             ABS_HAT0Y  ABS_MT_POSITION_X1    ABS_MT_POSITION_Y              ABS_RZ                 ABS_X                 ABS_Y              ABS_Z2             BTN_EAST         BTN_GAMEPAD             BTN_MOUSE             BTN_NORTH         BTN_SELECT3            BTN_START          BTN_THUMBL            BTN_THUMBR                BTN_TL            BTN_TL24               BTN_TR             BTN_TR2              BTN_WEST                 KEY_0              KEY_15            KEY_102ND               KEY_2                 KEY_3                 KEY_4              KEY_56                KEY_6               KEY_7                 KEY_8                 KEY_9              KEY_A7       KEY_APOSTROPHE               KEY_B              KEY_BACK         KEY_BACKSLASH      KEY_BACKSPACE8        KEY_BOOKMARKS               KEY_C              KEY_CALC          KEY_CAPSLOCK          KEY_COMMA9          KEY_COMPOSE        KEY_COMPUTER                 KEY_D            KEY_DELETE            KEY_DOT10            KEY_DOWN               KEY_E               KEY_END             KEY_ENTER          KEY_EQUAL11             KEY_ESC               KEY_F                KEY_F1               KEY_F10            KEY_F1112             KEY_F12             KEY_F13               KEY_F14               KEY_F15             KEY_F213              KEY_F3              KEY_F4                KEY_F5                KEY_F6             KEY_F714              KEY_F8              KEY_F9           KEY_FORWARD                 KEY_G          KEY_GRAVE15               KEY_H         KEY_HANGEUL             KEY_HANJA            KEY_HENKAN       KEY_HIRAGANA..."""# most of the keystrokes can be executed easily because almost all of them have their method.# You only have to pass the duration when calling themsendeventkey.press_dev_input_event10_u(2)# Will press the button for 2 secondsdir(sendeventkey)# ....# 'press_dev_input_event10_tr2',# 'press_dev_input_event10_u',# 'press_dev_input_event10_up',# 'press_dev_input_event10_v',# 'press_dev_input_event10_volumedown',# 'press_dev_input_event10_volumeup',# 'press_dev_input_event10_w',# 'press_dev_input_event10_wakeup',# 'press_dev_input_event10_west',# 'press_dev_input_event10_x',# 'press_dev_input_event10_y',# 'press_dev_input_event10_yen',# 'press_dev_input_event10_z',# 'press_dev_input_event10_zenkakuhankaku',# 'press_dev_input_event11_a',# 'press_dev_input_event11_abs_brake',# 'press_dev_input_event11_abs_gas',# 'press_dev_input_event11_abs_hat0x',# 'press_dev_input_event11_abs_hat0y',# 'press_dev_input_event11_abs_mt_position_x',# 'press_dev_input_event11_abs_mt_position_y',# 'press_dev_input_event11_abs_rz',# 'press_dev_input_event11_abs_x',# 'press_dev_input_event11_abs_y',# 'press_dev_input_event11_abs_z',# 'press_dev_input_event11_apostrophe',# 'press_dev_input_event11_b',# 'press_dev_input_event11_back',# 'press_dev_input_event11_backslash',# 'press_dev_input_event11_backspace',# ....Tested against Windows 10 / Python 3.9.13 / BlueStacks 5It should also work with any rooted Android device, butsince my cell phone is not rooted, and I have no intention of rooting it,I cannot test the module against a physical Android device.(I would be grateful for any feedback)