B4A Library SendInput - Emulate user input within your app

SendInput Library v0.2

* v0.2 31/03/2014
Added: SwipeParams - Now allowing the delay between each swipe pulse to be increased or decreased.
Moved: 'Step' parameter from SendSwipe to SwipeParams


This library allows you to emulate user input within the application. You can send key codes, a string of keys, a single touch tap, and swipe actions.

To begin using the library you simply define a variable:
B4X:
Sub Globals
    ' define a variable for the SendInput library
    Dim si As SendInput
End Sub

That's all. The following commands can now be used to send/emulate user input:

B4X:
' Send a single keycode
si.SendKeyCode(KeyCodes.KEYCODE_TAB)

' Send a string of keys
si.SendKeys("Hello")

' Send a touch tap to absolute coordinate 300,200
si.SendTap(300,200)

' Send a swipe action from absolute coordinates 60,70 to 200,300
si.SendSwipe(60,70 , 200,300)

' Change the swipe parameters.
' Here, the steps between each swipe point are set to 50 and the
' delay between each swipe point to 25ms.
' NOTE: It may be necessary to increase the delay for older devices in order
' to allow time for the system to pick up each swipe point.
si.SwipeParams(50,25)

The download link (below) includes a demo to test out the library.

SendInput_snap1_zps2d415751.png



Download the library from here - DOWNLOAD
 
Last edited:

Beja

Expert
Licensed User
Longtime User
Jim,
Thank you so much for this very very important library. This lib is specially important and useful for presentation and educational Apps.

God bless you!
 

carchek

Member
Licensed User
Longtime User
HI!
Your library is out of this world, just what I needed for my project!
But I have a question. How can I make, da app saves current location on screen and then after 5 seconds scrolls down until user presses a button?
I am using it as si.sendSwipe; And using it to scroll down a website opened in WebBrowser1.
Thanks.

Gregor
 

Jim Brown

Active Member
Licensed User
Longtime User
Hello Gegor,
You can achieve the above with a timer. See attached example.
Click Start AutoScroll button to begin the auto-scroll action. The webpage will scroll every 5 seconds.
Press the button again to stop the auto-scrolling.
 

Attachments

  • SendInput_ScrollWebPage.zip
    7.3 KB · Views: 575

Jim Brown

Active Member
Licensed User
Longtime User
Library updated. Added a SwipeParams setting applicable for the swipe action.
Note that the SendSwipe() Step parameter has now been moved to the SwipeParams().
 
Last edited:

G-ShadoW

Active Member
Licensed User
Longtime User
Is it possible to send 'service commands' with your library?
For example, on samsung mobile phone's you have many options for engineer menu.
*#0011# or *#197328640# etc, is this posible ?
I have try but without succsess.
 

G-ShadoW

Active Member
Licensed User
Longtime User
I have found a way to send non ussd commands like *#*#197328640#*#* all working ok (without your library)
but I cant send any command using si.SendKeyCode(KeyCodes.KEYCODE_MENU) etc...
can your library work also from service module ?
 

Jim Brown

Active Member
Licensed User
Longtime User
Hi G-ShadoW
My (simple) library can only mimic inputs to the program you create.
One idea, have you looked at Tasker in the Play store? This is a great tool and far more advanced in terms of allowing external control.
 

G-ShadoW

Active Member
Licensed User
Longtime User
Thx for reply, is there any other way to programaticaly send command for menu pressed?
 

Jim Brown

Active Member
Licensed User
Longtime User
Yes, but I don't have access to my PC for a while so I can't recall the name of the MENU keycode
Perhaps ...

si.SendKeyCode(KeyCodes.KEYCODE_MENU) ?
 

Jim Brown

Active Member
Licensed User
Longtime User
Does the sample demo work?
The SendKeys buttion runs a series of key strokes and single key clicks as follows:

B4X:
Sub btn_SendKeys_Click
    Select Rnd(1,8)
        Case 1 : si.SendKeys("Basic")
        Case 2 : si.SendKeys("Android")
        Case 3 : si.SendKeys("Hello")
        Case 4 : si.SendKeys(" ")
        Case 5 : si.SendKeys("123")
        Case 6 : si.SendKeyCode(KeyCodes.KEYCODE_DEL)
        Case 7 : si.SendKeyCode(KeyCodes.KEYCODE_MENU)
    End Select
End Sub
 

Herbert32

Active Member
Licensed User
Longtime User
Download the library from here - [URL='https://drive.google.com/folderview?id=0B1H1JEGSWcxjd3ZFWXRCclJYOXM&usp=sharing' said:
DOWNLOAD[/URL]

It seems that this Library has been deleted and stays in the authors Bin at google-drive.

Dear Jim, can you please make this library available again?

or maybe someone who downloaded it earlier can share it please?

upload_2018-6-6_16-6-11.png


thank you in advance.
 

Herbert32

Active Member
Licensed User
Longtime User
Thank you, Jim,

it works perfectly on my target device with android 4.2.2

great to see how the community here helps
 
Top