msloth / lgtv.js

Control LG WebOS TV using node.js
MIT License
249 stars 119 forks source link

+ add remote pointer control; - removed tailed spaces; #9

Closed rowdyroad closed 2 years ago

msloth commented 8 years ago

Great! I'll have a look soon, it looks good though.

ptruman commented 8 years ago

Hi - just found this - am very interested as I would love pointer control.
@rowdyroad - does this work for you? (I'm happy to patch my local copy with your delta) - what is the syntax for driving the cursor?

Thanks in advance :)

rowdyroad commented 8 years ago

Yes, it works. lgtv.input_pointer_move(dx,dy); lgtv.input_pointer_scroll(dx, dy); lgtv.input_pointer_click();

but lg's api has no command to set pointer at the current position, only move it by delta from last position.

ptruman commented 8 years ago

Excellent news, thanks for that @rowdyroad! Does it also have a simple "left/right/up/down" option? (the one thing I can't seem to drive via TCP is moving around menus easily - even with the standard lgtv node code)

ptruman commented 8 years ago

Update - post a bit of wiresharking to my TV, I've modded your code to add up/left/down/right and back functions. I don't have a pull/commit - so can paste here if you'd like?

rowdyroad commented 8 years ago

Ok, let's see your code.

ptruman commented 8 years ago

Not a "proper" github user and haven't pulled any code, so this is a hand edit. I've added input_pointer_left, input_pointer_right, input_pointer_up, input_pointer_down and input_pointer_back.

Once your pointer websocket connects, they are just sending "type:button\nname:DIRECTION\n\n" (where DIRECTION is the direction of choice.

I think "HOME" probably works as well, but haven't had a chance to try (I kludged the above with a toddler crawling on me!).

Code attached herein: index.js

I probably need to learn node somewhat better, as presently I'm using this in a node script, called via a bash script, called by OpenRemote (which I'm using to drive my A/V setup). It's annoyingly slower to require("lgtv") and open a pointer socket, than it is to use send an IR command over TCP to my itach IP2IR device, but it does mean I could remove the IR device. Just need to figure out a way to code a little listener/server that maintains a websocket and send commands to it! :)

rowdyroad commented 8 years ago

Ooohh... you have not understood my comment.

To move left you need to: lgtv.input_pointer_move(-1,0); if you want do it faster (for example, ten times): lgtv.input_pointer_move(-10,0);

Right: lgtv.input_pointer_move(1,0);

Down: lgtv.input_pointer_move(0,1);

Up: lgtv.input_pointer_move(0,1);

Diagonally (right-bottom): lgtv.input_pointer_move(1,1)

ptruman commented 8 years ago

It's quite possible :) In my command script that calls node, I'm doing (ignore function/error/response stuff) the following (assume I have the "Smart" ribbon showing at the bottom already)

lgtv = require("lgtv"); var tv_ip_address = "MY.IP.HERE"; lgtv.connect(tv_ip_address); lgtv.input_pointer_connect();

If I then do:

lgtv.input_pointer_right();

it moves focus to the next item on the right. If I try:

input_pointer_move(1,0) OR input_pointer_move(10,0) Or a larger integer

I get nothing (probably missing something!)