aka Blue Posted May 8, 2019 Share Posted May 8, 2019 So I want to do a simple YouTube simple to listen to music but I don't know what function or script use to inject text into a Browser. I'm using dxDrawImage to draw the browser because for me it's more editable. The mouse works perfectly but I need to make the keyboard work too. Thanks! --In order to render the browser on the full screen, we need to know the dimensions. local screenWidth, screenHeight = guiGetScreenSize() --Let's create a new browser in remote mode. local webBrowser = createBrowser(screenWidth, screenHeight, false, false) --Function to render the browser. function webBrowserRender() --Render the browser on the full size of the screen. dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true) end --The event onClientBrowserCreated will be triggered, after the browser has been initialized. --After this event has been triggered, we will be able to load our URL and start drawing. addEventHandler("onClientBrowserCreated", webBrowser, function() --After the browser has been initialized, we can load www.youtube.com loadBrowserURL(webBrowser, "http://www.youtube.com") --Now we can start to render the browser. addEventHandler("onClientRender", root, webBrowserRender) function onCursorMove ( relativeX , relativeY , absoluteX , absoluteY ) injectBrowserMouseMove ( webBrowser , absoluteX , absoluteY ) end addEventHandler ( "onClientCursorMove" , root , onCursorMove ) addEventHandler("onClientKey", root, onKey) addEventHandler("onClientClick", root, function(button, state) if state == "down" then injectBrowserMouseDown(webBrowser, button) else injectBrowserMouseUp(webBrowser, button) end end) end ) function onKey(button) if button == "mouse_wheel_down" then injectBrowserMouseWheel(webBrowser, -40, 0) elseif button == "mouse_wheel_up" then injectBrowserMouseWheel(webBrowser, 40, 0) end end Link to comment
Moderators IIYAMA Posted May 8, 2019 Moderators Share Posted May 8, 2019 https://wiki.multitheftauto.com/wiki/FocusBrowser Quote This function will attempt to focus the browser or unfocus all browsers. The browser that is focused will retrieve keyboard input. @aka Blue 1 Link to comment
aka Blue Posted May 8, 2019 Author Share Posted May 8, 2019 One more thing. When I modify the browser with the size and position I want, the click detecting it's working wrong. Like, I need to click the left corner of the screen to search or something like that. local sx, sy = guiGetScreenSize() local x, y = ( sx / 1024 ), ( sy / 768 ) local ancho, alto = 500, 500 local webBrowser = createBrowser(x*ancho, y*alto, false, false) function webBrowserRender() dxDrawImage((sx-x*ancho)/2, (sy-y*alto)/2, x*ancho, y*alto, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true) end function onKey(button) if button == "mouse_wheel_down" then injectBrowserMouseWheel(webBrowser, -40, 0) elseif button == "mouse_wheel_up" then injectBrowserMouseWheel(webBrowser, 40, 0) end end addEventHandler("onClientBrowserCreated", webBrowser, function() loadBrowserURL(webBrowser, "http://www.youtube.com") addEventHandler("onClientRender", root, webBrowserRender) function onCursorMove ( relativeX , relativeY , absoluteX , absoluteY ) injectBrowserMouseMove ( webBrowser , absoluteX , absoluteY ) end addEventHandler ( "onClientCursorMove" , root , onCursorMove ) addEventHandler("onClientKey", root, onKey) addEventHandler("onClientClick", root, function(button, state) if state == "down" then injectBrowserMouseDown(webBrowser, button) else injectBrowserMouseUp(webBrowser, button) end end) focusBrowser(webBrowser) end ) Link to comment
Moderators IIYAMA Posted May 9, 2019 Moderators Share Posted May 9, 2019 local webBrowser = createBrowser(sx, sy, false, true) -- + enable transparent executeBrowserJavascript ( webBrowser, [[document.getElementsByTagName('html').innerHTML += "<style>html {position:absolute; width: ]] .. x*ancho .. [[px; height:]] ..y*alto .. [[px; left: 50%; top: 50%; transform: translate(-50%, -50%); }</style>" ]] ) You might can solve it this way. Untested. @aka Blue Link to comment
Moderators IIYAMA Posted May 9, 2019 Moderators Share Posted May 9, 2019 (edited) executeBrowserJavascript ( webBrowser, [[document.getElementsByTagName('html')[0].innerHTML += "<style>html {position:absolute; width: ]] .. (x * ancho) .. [[px; height:]] .. (y * alto) .. [[px; left: 50%; top: 50%; transform: translate(-50%, -50%); }</style>" ]] ) * Edited May 9, 2019 by IIYAMA Link to comment
Moderators IIYAMA Posted May 10, 2019 Moderators Share Posted May 10, 2019 58 minutes ago, aka Blue said: @IIYAMA Not working Be more specific. What is the result? Also debug the newly added style DOM element: https://wiki.multitheftauto.com/wiki/ToggleBrowserDevTools Link to comment
Moderators IIYAMA Posted May 12, 2019 Moderators Share Posted May 12, 2019 4 minutes ago, aka Blue said: @IIYAMA I get that: that line of defence is not going to cut the butter. Link to comment
Moderators IIYAMA Posted May 12, 2019 Moderators Share Posted May 12, 2019 48 minutes ago, aka Blue said: if the javascript injection function is blocked because it is a remote browser, then there is not much we can do about. But you can try to use a second website with iframe which where you load the youtube page in. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe 1 Link to comment
aka Blue Posted May 12, 2019 Author Share Posted May 12, 2019 @IIYAMA I will test it. Thank you so much anyway! 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now