Page 1 of 2

help with the focus function

Posted: Sun May 05, 2013 10:28 pm
by thejaboy
i am trying to make a program hat well count every time the space bar is pressed, but it well only count when the window is in focus.
i would love help from anyone.

^_^

Re: help with the focus function

Posted: Mon May 06, 2013 2:53 am
by davisdude
A couple things:
1) Have you examined putting a love.focus in your main.lua?

Code: Select all

function love.focus(bool) --Run if mouse goes in or out of window
end
What this does is checks if your mouse is in or out of the window. (Bool is short for boolean, a true or false conditional. See more here: http://en.wikipedia.org/wiki/Boolean_data_type.)

If you need an example, the code should look something like this:

Code: Select all

function love.load() --Run only at start of game
	num = 0
end

function love.draw() --Run every time game can
	love.graphics.setColor( 255, 255, 255 )
	love.graphics.print( num, love.graphics:getWidth()/2, love.graphics.getHeight()/2 )
end

function love.update(dt) --Run every time the game can
end

function love.focus(bool) --Run if mouse goes in or out of window
end

function love.keypressed( key, unicode ) --Run if key is pressed
	if key == ' '  then
		num = num + 1
	end
end

function love.keyreleased( key, unicode ) --Run if key is released
end

function love.mousepressed( x, y, button ) --Run if mouse is pressed
end

function love.mousereleased( x, y, button ) --Run if mouse is released
end

function love.quit() --Run right before game is closed
end
2) For future reference, it is easier if you post the code and a .love version of the file for us to know how to fix it.

If you have any questions, just feel free to ask! :awesome:

Re: help with the focus function

Posted: Mon May 06, 2013 3:19 am
by thejaboy
yes i have that function, and when it runs then it will only count the space bar only when the program in focus.
i want the program to run i the back gound. When the program is done it should count the number of times one hits a key (or if i can a word)
and then print the amout of times its pushed.

^_^

Re: help with the focus function

Posted: Mon May 06, 2013 3:23 am
by slime
LÖVE will only process keyboard input when the window has the system's keyboard focus. It can't be used as a key logger.

Re: help with the focus function

Posted: Mon May 06, 2013 3:29 am
by thejaboy
is there any way to use lua/love engine as a
slime wrote:key logger.
?

Re: help with the focus function

Posted: Mon May 06, 2013 9:30 am
by Robin
thejaboy wrote:is there any way to use lua/love engine as a
slime wrote:key logger.
?
No. Why would you want to?

Re: help with the focus function

Posted: Mon May 06, 2013 8:54 pm
by davisdude
thejaboy wrote:yes i have that function, and when it runs then it will only count the space bar only when the program in focus.
i want the program to run i the back gound. When the program is done it should count the number of times one hits a key (or if i can a word)
and then print the amout of times its pushed.

^_^
OH! Sorry, I misunderstood your question. :P
Nope, not to my knowledge. You could look into a library/modification of some sort.

Re: help with the focus function

Posted: Tue May 07, 2013 1:28 am
by thejaboy
ok thank you

Re: help with the focus function

Posted: Tue May 07, 2013 3:55 am
by thejaboy
Ok, I have spent the last two hours looking for a modified love engine or a way to disable the focus function and i cant find anythimg.
I also think there has been a misunderstanding, i am not trying to make a key logger. the program when/if i finesh it will count
words or spaces for my brother who is a translater, and this program hopfuly will help him more accurately charch the people he works for.

so fare this is all i have done {
function love.load()
love.graphics.setBackgroundColor( 255, 255, 255 )
B = 0
end

function love.draw()
love.graphics.setColor( 0, 0, 0 )
love.graphics.print( "you have pushed the spacebar " .. B, 5, 5, 0, 1, 1 )
end

function love.update(dt)
end

function love.focus(bool)
end

function love.keypressed( key, unicode )

if love.keyboard.isDown(" ") then
B = B + 1
end
end

function love.keyreleased( key, unicode )
end

function love.mousepressed( x, y, button )
end

function love.mousereleased( x, y, button )
end

function love.quit()
end}

my problum is the focus function i would like to disable or trick or stop or somthing so the program will still count the space bar even if
the program is not in focus. any help would be... well helpful.

^_^

Re: help with the focus function

Posted: Tue May 07, 2013 7:58 am
by Plu
Why not just download an existing program that does just this?

Something like WhatPulse might do everything you want.

(Of course, if you want to program such a tool yourself, that's cool, just making sure you know you're making something that already exists.)