LABSN / expyfun

Experimental paradigm functions.
BSD 3-Clause "New" or "Revised" License
13 stars 21 forks source link

ec.refoucs() doesn't bring window to the front #446

Closed tomstoll closed 1 year ago

tomstoll commented 1 year ago

Calling ec.refoucs() grabs keyboard focus, but the window remains behind the IDE. Adding _user32.SetWindowPos(m_hWnd, -1, 0, 0, 0, 0, 0x0001 | 0x0002) to the refocus function solves the issue (I put it at line 2180 of _experiment_controller.py). Equivalent code is already in the function, but commented out. Is there a reason it's not used?

tomstoll commented 1 year ago

I also find that the following lines (2182, 2187)

_user32.AttachThreadInput(dwCurID, dwMyID, True)
_user32.AttachThreadInput(dwCurID, dwMyID, False)

are all that's required to set keyboard focus to the experiment window (at least on our computer). But the other functions don't seem to be hurting anything, so it's probably best to leave them?

larsoner commented 1 year ago

Did you test both windowed and fullscreen mode?

BTW back when we first worked on this in Windows 7, the only way we could guarantee accurate flip timing was in fullscreen mode. No idea if that's still the case in Windows 10+...

Is there a reason it's not used?

Could be it broke something at some point, or didn't have any effect. But if it works for you in both windowed and fullscreen mode let's trust how it works nowadays!

But the other functions don't seem to be hurting anything, so it's probably best to leave them?

I would leave them for backward compat I guess.

PR welcome for these changes! No real way to add tests for this stuff, so I'll have to trust your manual testing :)

tomstoll commented 1 year ago

I just did a quick test with both full screen and windowed mode. Everything seems to work as expected, I'll make a PR when I get a chance.

Maybe worth noting, the computer we're using now runs windows 10. We still have our old computer that runs windows 7, so I'll hook it back up and see if the change breaks anything.

tomstoll commented 1 year ago

As far as I can tell, it doesn't seem to break anything. However, it also isn't necessary on our old computer. I'm not sure if it's because it's an older version of Spyder or because it's Windows 7, but the experiment window is brought to the front when it's created even without calling ec.refoucs().