This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HPWebcamAble's profile picture

Capture computer screen

Started by HPWebcamAble, 11 July 2015 - 11:48 PM
HPWebcamAble #1
Posted 12 July 2015 - 01:48 AM
It would be awesome if I could take a picture of a computer screen. Without having to write the code myself. I'm occupied with something else right now.


Unfortunately, I may have to, searching for 'screenshot' on the forums brought up this:
http://www.computercraft.info/forums2/index.php?/topic/6450-screenshot-api/

It uses 'term.native', which doesn't work anymore, but changing it to 'term.current()' makes it function correctly!

But for some strange reason, the author had it save files in 'rtf format', or Rich Text Format.
I haven't the faintest clue as to why, a screenshot looks like this:
Spoiler

{\rtf1{\fonttbl{\f0\fnil\fcharset0 Courier New;}}{\colortbl;\red240\green240\blue240;\red235\green136\blue68;\red195\green84\blue205;\red102\green137\blue211;\red222\green222\blue108;\red65\green205\blue52;\red216\green129\blue152;\red67\green67\blue67;\red153\green153\blue153;\red40\green118\blue151;\red123\green47\blue190;\red37\green49\blue146;\red81\green48\blue26;\red59\green81\blue26;\red179\green49\blue44;\red30\green27\blue27;\red0\green0\blue0;}\sa0\cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \highlight0\par\cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17  \cf1\highlight17
The whole file is much longer than this. And 1 line.



So does anyone have a screenshot API / Program that saves in a format that can actually be displayed?
Bomb Bloke #2
Posted 12 July 2015 - 02:13 AM
The only one I'm aware of is Lightshot, but it's not like I've ever really looked.

Exactly what sort of format did you want? Displayable where?
HPWebcamAble #3
Posted 12 July 2015 - 02:20 AM
I thought of Lightshot as well, but I believe it can only record the screen, it can't do pictures.


WHY I wanted this is pretty simple: I'm Lazy
When I make GUIs, it usually takes a few tries before I can get buttons and text centered and looking nice.
I wanted a simple program to display a static image of a screen that could be clicked, telling you the coordinates of where you did so.

The whole 'tell you where you clicked' thing is easy, its the capturing-the-image part I'm kinda stuck on.

As for format, I don't really care, but it has to store colors and text (obviously)


I could write the program myself, if I have to, but I'd rather not if one already exists.
Edited on 12 July 2015 - 12:22 AM
Bomb Bloke #4
Posted 12 July 2015 - 02:43 AM
I'm hesitant to suggest anything making use of coroutines - as I seldom see them used correctly - but it strikes me that they'd make it fairly easy to do what you want.

Say you used this as a base, and rigged it so that when "paused" is true, mouse_click events trigger screen writes of the position - that should do the trick.
Grim Reaper #5
Posted 12 July 2015 - 04:10 AM
Maybe something like this? It's Bomb Bloke's suggestion implemented specifically for what you wanted. You just have to change the value of 'programPath' to point to the program you want to be able to pause.


local programPath = "/stuff"
local program = coroutine.create(
	setfenv(
		loadfile(programPath),
		setmetatable({ shell = shell }, { __index = _G })
	)
)

coroutine.resume(program) -- Initialize the program.


local paused = false

while coroutine.status(program) ~= "dead" do
	local eventData = { os.pullEvent() }

	-- Toggle pause.
	if eventData[1] == "key" and eventData[2] == keys.home then
		paused = not paused

		-- Neutralize event.
		eventData = {}
	end

	-- Distribute events if the program isn't paused.
	if not paused then
		coroutine.resume(program, unpack(eventData))
	-- Display mouse click if paused.
	elseif eventData[1] == "mouse_event" then
		term.setBackgroundColor(colors.black)
		term.setTextColor(colors.white)

		term.setCursorPos(1, 1)
		term.write("(" .. eventData[3] .. ", " .. eventData[4] .. ")")
	end
end
Edited on 12 July 2015 - 02:44 PM
HPWebcamAble #6
Posted 12 July 2015 - 06:52 AM
Very nice, I hadn't thought of doing it that way, it makes it much simpler.

Thanks for the help guys :)/>