help with the focus function

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
thejaboy
Prole
Posts: 8
Joined: Sun May 05, 2013 10:07 pm

help with the focus function

Post 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.

^_^
^_^
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 »

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:
Attachments
counter.love
Not very optimized, just a little example...
(902 Bytes) Downloaded 103 times
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 »

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.

^_^
^_^
User avatar
slime
Solid Snayke
Posts: 3159
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: help with the focus function

Post 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.
User avatar
thejaboy
Prole
Posts: 8
Joined: Sun May 05, 2013 10:07 pm

Re: help with the focus function

Post by thejaboy »

is there any way to use lua/love engine as a
slime wrote:key logger.
?
^_^
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 »

thejaboy wrote:is there any way to use lua/love engine as a
slime wrote:key logger.
?
No. Why would you want to?
Help us help you: attach a .love.
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 »

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.
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 »

ok thank you
^_^
User avatar
thejaboy
Prole
Posts: 8
Joined: Sun May 05, 2013 10:07 pm

Re: help with the focus function

Post 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.

^_^
^_^
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: help with the focus function

Post 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.)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests