Newbie external maker questions

Are you developing an External using the LiveCode Externals SDK?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Newbie external maker questions

Post by sturgis » Fri Mar 16, 2012 11:09 pm

I finally built an extremely simple external that actually works! (yay!) All it does is click the mouse at its current location. As it sits I take no arguments and return no results from the command, it just does its thing and works.
First question.. Is returning nothing from an external command a bad thing? Even with something this simple?

Second question. The current method of the external, just to get something to work, I have both the mouse click and mouse release in the same command. I'll probably change this soon so that it matches the state of a remote (meaning android) button on a home built android remote control app. If anyone has done similar before, do I need to worry about the mouse getting "stuck" down? (say if I have a button that when clicked and held sends a mouse down to remote machine.. if I drag off the button before releasing, the mouseup is NOT sent to the button correct?) Ok, this one I can just test. *doh*

Third question. From what I can tell, using a scroll wheel is just a rawkeydown event. So if I wish to have the ability remote scroll I should be able to have the external simulate that keypress, or am I way off base?

Any other things I might watch out for that could come back to get me?

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Newbie external maker questions

Post by mwieder » Fri Mar 16, 2012 11:29 pm

First of all, congratulations on getting it working. :P

Q1: returning nothing is the canonical success case. Normally I use an empty return to signal success and otherwise return an error string.
Q2: If I'm understanding you correctly, your assumptions are correct. There will be no mouseUp event if the mouse is moved off the control before releasing. I usually handle the mouseDown, mouseUp, mouseEnter, mouseLeave, mouseRelease events as a set because of this.
Q3: Yes, I intercept scrollwheel events as rawKeyDown events and process them there. So simulating the rawKeyDown event and testing for the keyCode is the way to go.

Q4: There is no external support for Android at this point.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Newbie external maker questions

Post by sturgis » Fri Mar 16, 2012 11:48 pm

Thanks much, i'm tickled to have made my first successful doohickey.

As for question 4, luckily it doesn't apply in this situation. The external will be used on my laptop (aka tv controller) system. Though this does bring up the next question.
Its not too difficult to set up a simple client/server thing, but there are no sockets yet on android right? In which case I'm thinking that I can instead use andres' http stack and revonrockets stuff (works REALLY well) and use http: strings for control, but i'm not to the point of testing that portion of things yet so not sure if there might be a speed issue. I'm hoping to do cursor position control, clicks, right clicks, and as mentioned, the rawkeyups and downs for scrolling purposes.
Could also go with lc server to do the same thing, send almost nothing, return almost nothing should be pretty fast i'm thinking but am not sure about the overhead of the connect, send, receive, disconnect for each little thing.
*ponders* so. Um. Are sockets for android coming soon? *grin*
mwieder wrote:First of all, congratulations on getting it working. :P

Q1: returning nothing is the canonical success case. Normally I use an empty return to signal success and otherwise return an error string.
Q2: If I'm understanding you correctly, your assumptions are correct. There will be no mouseUp event if the mouse is moved off the control before releasing. I usually handle the mouseDown, mouseUp, mouseEnter, mouseLeave, mouseRelease events as a set because of this.
Q3: Yes, I intercept scrollwheel events as rawKeyDown events and process them there. So simulating the rawKeyDown event and testing for the keyCode is the way to go.

Q4: There is no external support for Android at this point.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Newbie external maker questions

Post by mwieder » Sat Mar 17, 2012 12:02 am

Right. Sockets would be the way to go since externals aren't available.
Since sockets aren't available either, revHTTP might be the way to go.
If only it didn't use sockets.
AFAIK libURL isn't available on Android.

I could be wrong on this (Andre'd have to chime in here) and maybe all this will work on Android now.
Otherwise we just have to wait. AnDevCon is two months away now, and I'm hoping the rev team will have *something* to show by then.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Newbie external maker questions

Post by sturgis » Sat Mar 17, 2012 12:06 am

Argh! I will find a way. Even if "the way" is to wait for updates on android!

Thanks very much for the info and guidance, its appreciated.
mwieder wrote:Right. Sockets would be the way to go since externals aren't available.
Since sockets aren't available either, revHTTP might be the way to go.
If only it didn't use sockets.
AFAIK libURL isn't available on Android.

I could be wrong on this (Andre'd have to chime in here) and maybe all this will work on Android now.
Otherwise we just have to wait. AnDevCon is two months away now, and I'm hoping the rev team will have *something* to show by then.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Newbie external maker questions

Post by sturgis » Sat Mar 17, 2012 3:08 am

Got things working. YAY!

Running andre's http and revonrockets on my desktop, added 2 commands so far to the libcgidemo stack that he provides with it.
doClick is executed when this url is hit
http://localhost:8082/libcgidemo.rev?cmd=doClick
Local network only of course.
The mouse is moved by
localhost:8082/libcgidemo.rev?cmd=moveMouse&x=pixelstomove&y=pixelstomove so x=5 and y= 5 will move the cursor right 5, down 5. negative numbers reverse
currently only have 1 command in my external, it does mouse click and mouse release on call, so currently no dragging, no right click.

Code: Select all

command moveMouse
   put the screenmouseloc into tLoc
   add gRequestA["x"] to item 1 of tLoc
   add gRequestA["y"] to item 2 of tLoc
   set the screenmouseloc to tLoc
   libCGI_Response("moved to" &&  tLoc),"text/plain"
   put tLoc
   put gRequestA["x"] && gRequestA["y"] after msg
end moveMouse

command doClick
   clickit
   libCGI_Response ("0"), "text/plain"         
end doClick
For the android app I have the following code.

Code: Select all

local sMoving,sButton,lastX,lastY -- declare script locals
constant kMoveUrl="http://192.168.254.113:8082/libcgidemo.rev?cmd=moveMouse&x=[[x]]&y=[[y]]" -- my mousemove url constant

on touchStart -- on touch start
   switch the short name of the target
      case "lClick" -- if its a button either left or right, just click
         get URL "http://192.168.254.113:8082/libcgidemo.rev?cmd=doClick"
         --get URL "http://192.168.254.113:8082/libcgidemo.rev?cmd=rightClick"
         break
      case "rClick"  -- would have a right click here but its not in the external yet
         get URL "http://192.168.254.113:8082/libcgidemo.rev?cmd=doClick"
         --get URL "http://192.168.254.113:8082/libcgidemo.rev?cmd=leftClick" 
         --put "r" into sButton
         break
      case "trackPad" -- if touch starts on the card then we're gonna move the cursor
         put true into sMoving
   end switch
end touchStart

on touchEnd
   put false into sMoving -- clear vars and reset for next whatever. 
   put empty into lastx
   put empty into lasty
end touchEnd

command touchMove pTouchId,pX,pY
   if lastX is empty then put pX into lastX -- track the starting location of the touch, both x and y
   if lastY is empty then put pY into lastY
   if sMoving then -- if moving then
      put pX - lastx into x -- find the difference in last x and current x position and store it in x
      put pY - lasty into y -- same for y
      put px into lastx -- update the last x position
      put py into lasty -- same fory
      put merge(kMoveUrl) into tUrl -- create the url to do the move
      get URL tUrl -- do the actual move
   end if
   
end touchMove
Now.. I've gone braindead and just can't seem to figure out how to implement a tap click into this scenario. I would accept suggestions gladly, otherwise going to sleep on it tonight.

Thx for the help earlier MW, much appreciated!

Oh, if anyone is interested in the bare minimum 'clicky' external I wouldn't mind sharing, or I can just provide the few lines of code that accomplish it. Otherwise I'll wait till it's fleshed out a bit more and working in a better way.

Oh, Thanks andre!

Post Reply

Return to “Building Externals”