Page 2 of 2
Re: help with the focus function
Posted: Tue May 07, 2013 8:38 am
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.
Re: help with the focus function
Posted: Tue May 07, 2013 9:58 pm
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
Re: help with the focus function
Posted: Wed May 08, 2013 12:33 am
by davisdude
Okay, since I gave you such a bad first answer (sorry about that
) 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!
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!
Re: help with the focus function
Posted: Wed May 08, 2013 2:56 am
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.
Re: help with the focus function
Posted: Wed May 08, 2013 3:36 am
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.
Re: help with the focus function
Posted: Wed May 08, 2013 3:56 am
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.
Re: help with the focus function
Posted: Wed May 08, 2013 3:03 pm
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.
Re: help with the focus function
Posted: Wed May 08, 2013 8:28 pm
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.