Detecting Input Without Window Focus (Listen For Input In The Background)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Baggef
Prole
Posts: 9
Joined: Fri Aug 23, 2019 7:30 pm
Location: USA
Contact:

Detecting Input Without Window Focus (Listen For Input In The Background)

Post by Baggef » Mon Sep 16, 2019 4:43 pm

Is it possible to detect input while the window is not focused?

I've tried using love.window.hasFocus(), and it did update while the window did not have focus.

Code: Select all

function love.update(dt)
	if love.window.hasFocus() == false then
		print("No Focus")
	end
end
But detecting input while in the background doesn't seem to work with hasFocus()

Code: Select all

function love.update(dt)
	if love.window.hasFocus() == false and love.keyboard.isDown('k') then
		print('k')
	end
end
Any help is greatly appreciated.
gaeem defelpmint is maiy pashin
Itch: Freakman
Twitter: baggefArt

User avatar
zorg
Party member
Posts: 2697
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Detecting Input Without Window Focus (Listen For Input In The Background)

Post by zorg » Mon Sep 16, 2019 5:42 pm

No, it's not possible through regular means.
(Edit: It's not completely impossible, but achieving it requires os-specific lower level workarounds)
Last edited by zorg on Tue Sep 17, 2019 5:07 am, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
raidho36
Party member
Posts: 1899
Joined: Mon Jun 17, 2013 12:00 pm

Re: Detecting Input Without Window Focus (Listen For Input In The Background)

Post by raidho36 » Mon Sep 16, 2019 11:30 pm

SDL is a gaming-centric framework and games are not meant to capture input while in background. Implementation-wise, SDL polls input from a window, if it loses focus then there's no input events.

User avatar
pgimeno
Party member
Posts: 1819
Joined: Sun Oct 18, 2015 2:58 pm

Re: Detecting Input Without Window Focus (Listen For Input In The Background)

Post by pgimeno » Tue Sep 17, 2019 9:37 am

The whole concept of focus is about where to send input events, isn't it?

Imagine you are typing in an editor, then change window to a web form, and what you type in the web form is typed in the editor. [EDIT: Or that you press F1 for help in one application, and every other open application opens the help.]

It is possible for certain applications to receive certain inputs when not focused, for example a music player in the background can receive multimedia keys, but as raidho implied, SDL is not prepared for that.
Last edited by pgimeno on Tue Sep 17, 2019 11:41 am, edited 1 time in total.

User avatar
zorg
Party member
Posts: 2697
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Detecting Input Without Window Focus (Listen For Input In The Background)

Post by zorg » Tue Sep 17, 2019 11:00 am

I faintly remember someone saying that you can still detect joystick/gamepad stuff even when unfocused though, if not keyboard/mouse.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.


Post Reply

Who is online

Users browsing this forum: Bing [Bot], YounYokel and 5 guests