Jump to content

[BROWSER] Inject text to browser


Recommended Posts

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

brxBDmQ.png

Link to comment

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
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
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 by IIYAMA
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...