Android Question Is there a way to simulate a click?

Rorry

Member
Licensed User
Longtime User
Hi,
how can i simulate a click (touch event) on my own application at a specific X Y point on the screen.

Thanks.
 

Informatix

Expert
Licensed User
Longtime User
i did a try this way,with reflector library,this works well on button,panel... but what i'm trying to do,its to simulate a click on a webview object (on a flash player to be specific)
to me,the better way should be focusing on "dispatchTouchEvent" & "MotionEvent" like this example
http://stackoverflow.com/questions/9787699/programmatically-execute-touch-event-in-android

thank you for your help.
The donationware version of the Gesture Detector library can do this (with CreateMotionEvent and PassTouchEventTo).
 
Upvote 0

Rorry

Member
Licensed User
Longtime User
Thank you informatix.

It sounds good. I'll donate you soon what i can for this useful library ;)

thanks everyone for help.
 
Upvote 0

Rorry

Member
Licensed User
Longtime User
Pretty good idea eric. didnt think about that.

but when i try :
B4X:
webview1.LoadUrl("javascript:document.elementFromPoint(250, 250)).click();")

i get this error : Uncaught TypeError: Object #<HTMLEmbedElement> has no method 'click' in null (Line: 1)

any idea? thx
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Pitty! I assume all that is needed is a couple of lines of code. As B4A user, refering to a Javascript webpage (about the MotionEvent) does not help very much. What I don't understand is how a Gestures Detector can generate gestures by means of code as you seem to reply in thread #4 in reply to Rorry. Please give a bit more guidance, if you can. I doubt whether Rorry solved his problem either....
I never used a webview since I started writing code in B4A so I won't be of great help here.
And AFAIK, GD solved the problem of Rorry.
In PassTouchEvent, GD dispatches the motion event to another view. There's no wizardry. It's a thing that can be done in Java.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
OK, it was not clear to me that support is linked to a (compulsary) donation. I have made a donation 5 minutes ago.
Could you please send version 2.2 of your GD library (as soon as possible)? It took me some time to figure out why I could not find the "createmotionevent" feature in my version of GD (because I was using an older version...
There is also confusion between the "Gestures" and the "Gestures Detector" library; both often use "GD" as variable.
Thank you for your donation.

What the D means in "GD" for the Gestures library ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Informatix

Expert
Licensed User
Longtime User
that a move can also be done with your GD library (e.g. by using ACTION_MOVE), which also does not work.
Without CreateMotionEvent, I don't see how you can generate a move with the library.

Is it possible to use GD to simulate a MOVE action by code? If so, please don't reply with a simple "yes" but tell me how to do it.
Set the action parameter of CreateMotionEvent to Action_Move and generate at least two moves (in case the scrolling function does not take into account the initial position of Action_Down).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I'm amazed that you have to simulate all these operations with a webview. There's no function to scroll a webview? To select and click on a link?

Not with a simple webview. With webviewextras library you have part of this features

flingScroll(webView1 As WebView, vx As Int, vy As Int)
flingScroll is a poorly documented method of the WebView.
It's included in WebViewExtras as it may be useful but i can find no documentation for it or it's parameters.

vx and vy do not seem to be pixel values - i suspect they are velocity values for the kinetic/fling scroll.

pageDown(webView1 As WebView, scrollToBottom As boolean)

Scroll the contents of webView1 down by half the page size.

scrollToBottom - If true then webView1 will be scrolled to the bottom of the page.

Returns a Boolean value to indicate the success or failure of the scroll.

pageUp(webView1 As WebView, scrollToTop As boolean)

Scroll the contents of webView1 up by half the page size.

scrollToTop - If true then webView1 will be scrolled to the top of the page.

Returns a Boolean value to indicate the success or failure of the scroll.
 
Upvote 0
Top