help with the focus function

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: help with the focus function

Post by micha »

Plu wrote:Why not just download an existing program that does just this?
I'd even go so far and say that any proper text processing software has a word counting feature already. So you don't even need to download anything.
User avatar
thejaboy
Prole
Posts: 8
Joined: Sun May 05, 2013 10:07 pm

Re: help with the focus function

Post by thejaboy »

This is close to what I am trying to make, but I'm trying to make something he can use once when he needs it and turns off when he doesnt
^_^
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: help with the focus function

Post by davisdude »

Okay, since I gave you such a bad first answer (sorry about that :P ) I felt obliged to put more thought into it...
And I thought: why not have the program act as where they log the translation? So I put some thought into it, and came up with this:

Code: Select all

function love.load()
	love.graphics.setBackgroundColor( 255, 125, 0 )
	length = 0
	text = {}
	text[0] = {}
	text[0].letter = ""
	text[0].x = 100
	text[0].y = 100
	
	spaces = 0
end

function love.keypressed( key ) --unicode might be better if they use a foreign keyboard. Check out this site for unicode characters: http://en.wikipedia.org/wiki/List_of_Unicode_characters
	if key == 'backspace' then
		if length > 0 then
			if text[length].letter == " " then
				spaces = spaces - 1
				if spaces < 0 then
					spaces = 0
				end
			end
			table.remove( text[length], text[length].key )
			text[length].letter = ""
			length = length - 1
		end
		if length < 0 then
			length = 0
		end
	elseif key == 'delete' then
		for i = 0, #text do
			text = {}
			text[0] = {}
			text[0].letter = ""
			text[0].x = 100
			text[0].y = 100
			spaces = 0
			length = 0
		end
	elseif key == 'return' then
		length = length + 1
		text[length] = {}
		text[length].letter = ""
		text[length].x = text[0].x
		text[length].y = text[length-1].y + 15
	else
		length = length + 1
		text[length] = {}
		text[length].letter = key
		text[length].x = text[length - 1].x + 7
		text[length].y = text[length - 1].y
		if key == ' ' then
			spaces = spaces + 1
		end
	end
end

function love.draw()
	for i = 0, #text do
		love.graphics.setColor( 255, 255, 255 )
		love.graphics.print( text[i].letter, text[i].x, text[i].y )
	end
	love.graphics.setColor( 255, 255, 255 )
	love.graphics.print( "Length: "..length.."", 650, 550 )
	love.graphics.print( "Spaces: "..spaces.."", 725, 550 )
end
I hope this works! :awesome:
P.S.: I never got around to figuring out what the default text is called, but if you do, you can make it look better by changing

Code: Select all

text[length].x = text[length - 1].x + 7
to

Code: Select all

text[length].x = text[length-1].x + NAME:getWidth(text[length]) + 1
The one is so that it doesn't look so jumbled.
If you need to make it so that if his typing goes off the page it'll go to a new line I can do that for you.
Happy coding! :awesome:
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
thejaboy
Prole
Posts: 8
Joined: Sun May 05, 2013 10:07 pm

Re: help with the focus function

Post by thejaboy »

thank you davisdude, but all i need is a way to disable the focus function. is there a way to get into the love engine and disable it or i the config file?
that is all i need, the rest of it i can write myself.
^_^
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: help with the focus function

Post by davisdude »

Not that I know of. But why couldn't you just use Love itself AS the key logger? In the corner of my code it even displays how many times space has been pressed.
B.T.W.: If you end up using my code you can press delete to clear all of the text if you don't want to press backspace a bunch.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
thejaboy
Prole
Posts: 8
Joined: Sun May 05, 2013 10:07 pm

Re: help with the focus function

Post by thejaboy »

i cant becouse when the love window is no longer in focus the program wont count. it just sites there mocking me... if i cant get it to work with love i may need to find another engine or languags to write it in.
^_^
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: help with the focus function

Post by Robin »

You need to find a low-level API if you want to write this yourself. It would depend on your brother's operating system which one. LÖVE itself only gets key events from SDL, which doesn't know about key presses that occur when its window is not in focus.
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: help with the focus function

Post by Jasoco »

I know Java can do this. I've seen an app written in Java that records all your mouse movements in the background and draws a neat art image of your mousing throughout the day. If you really need to capture input in the background you might want to look into it.

If Java weren't so hard to learn for me I'd probably be using it instead. Lua's just so easy to understand coming from a QBASIC background.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 0 guests