adb shell input help produces (after a long list of input devices):
The commands and default sources are: text <string> (Default: touchscreen) keyevent [--longpress] <key code number or name> ... (Default: keyboard) tap <x> <y> (Default: touchscreen) swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) press (Default: trackball) roll <dx> <dy> (Default: trackball)
So, it seems that the "text" is really virtual (default: touch) and keyevent for the physical (default: keyboard).
You can override the text input device - adb shell input keyboard text "foo" works fine. You cannot send raw key codes from the screen.
source share