SFML community forums
Help => General => Topic started by: Ectance on November 24, 2011, 09:22:52 pm
-
i have this code :
while(true)
{
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Num1))
smFunction = 0;
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Num2))
smFunction = 1;
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Num3))
smFunction = 2;
std::cout<<smFunction<<std::endl;
}
and it works as expected , but if i try to get function key state the input get stucked :
while(true)
{
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F10))
smFunction = 0;
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F11))
smFunction = 1;
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F12))
smFunction = 2;
std::cout<<smFunction<<std::endl;
}
if i click on the screen rapidly the values are changing but if not , the value of <smFunction> get stuck at the previous value at a random time . also when stuck , i think the window loses focus for a second.
is this a bug or I'm doing it wrong ?
ps. im using sfml 2.0 ( 1-2max week snapshot ) on win7x32 machine
ps2. sorry for my english
-
Could you please provide a complete and minimal example that reproduces the problem?
-
void loop()
{
smTerminate = false;
smUiMode = SM_UIMODE_CONSOLE;
while(!smTerminate && render_window->IsOpened())
{
switch(smUiMode)
{
case SM_UIMODE_CONSOLE:
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F10))
{
std::cout<<"0\n";
smConsoleActive = 0;
}
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F11))
{
std::cout<<"1\n";
smConsoleActive = 1;
}
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F12))
{
std::cout<<"2\n";
smConsoleActive = 2;
}
while (render_window->PollEvent(evt))
{
if(evt.Type == sf::Event::TextEntered)
{
switch(evt.Key.Code)
{
case 100 :
// do stuff :
break;
}
}
}
console[smConsoleActive].Display(render_window);
break;
default:
;
}
}
}
if i replace F10,F11 and F12 with Num1 Num2 and Num3 it works fine
-
complete
minimal
http://www.sfml-dev.org/forum/viewtopic.php?p=36368#36368
;)
-
#include <SFML/Config.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow *render_window;
sf::ContextSettings render_settings;
unsigned char smConsoleActive = 0;
sf::Event evt;
render_settings.AntialiasingLevel = 0;
render_settings.DepthBits = 0;
render_settings.MajorVersion = 2;
render_settings.MinorVersion = 0;
render_settings.StencilBits = 0;
render_window = new sf::RenderWindow(sf::VideoMode(1024,768,32),"win",sf::Style::Titlebar | sf::Style::Close,render_settings);
bool terminate = false;
while(!terminate && render_window->IsOpened())
{
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F10))
{
std::cout<<"0\n";
smConsoleActive = 0;
}
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F11))
{
std::cout<<"1\n";
smConsoleActive = 1;
}
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::F12))
{
std::cout<<"2\n";
smConsoleActive = 2;
}
while (render_window->PollEvent(evt))
{
if(evt.Type == sf::Event::TextEntered)
{
switch(evt.Key.Code)
{
case 100 :
// do stuff :
break;
}
}
}
render_window->Clear();
render_window->Display();
}
delete render_window;
return 0;
}
so if you press fast the three F-keys the output in std::cout is wrong ~50% of the time
-
no one ?
-
I'll test it as soon as I can.
-
Yes, you're right, something goes wrong when typing those keys fast. I don't know what's going on.
-
The problem is with the F10 key on Windows. It has a special meaning for the OS (don't know which one though), and pressing it seems to enter a state where other keys are ignored until you press it again.
I can probably disable this special behaviour in SFML, but first I'd like to find what it's supposed to mean for the OS.
-
I don't know if it helps but I found this :
F10 :
- In Microsoft Windows activates the menu bar of an open application.
- Access the hidden recovery partition on HP and Sony computers.
(source) (http://www.computerhope.com/issues/ch000306.htm)
-
See this page:
http://devmaster.net/forums/topic/8587-help-with-wm-keydown-sc-keymenu-f10-key-press/
I ran into this myself, and I solved this by changing the SFML library in WindowImplWin32::GlobalOnEvent as follows.
Before:
// We don't forward the WM_CLOSE message to prevent the OS from automatically destroying the window
if (message == WM_CLOSE)
return 0;
After:
// We don't forward the WM_CLOSE message to prevent the OS from automatically destroying the window
if (message == WM_CLOSE)
return 0;
// We don't forward WM_SYSKEYDOWN and WM_SYSKEYUP messages for VK_F10 and
// the alt keys to prevent Windows from pausing the game and trying to
// activate a menu bar.
if (((message == WM_SYSKEYDOWN) || (message == WM_SYSKEYUP)) &&
((wParam == VK_F10) || wParam == VK_MENU))
{
return 0;
}
Laurent, feel free to use this in the official library code if you like, and it seems reasonable to you. :)
-
Any news on this ? This is a pretty old thread, yet the issue is still present. Is the solution GAFBlizzard proposed a bad one ? If so, what would be a better one ? If not, what prevents it from being merged into the main repository ?
-
Nothing new, my last reply still applies.
And yes, the given solution is the good one.
-
I can probably disable this special behaviour in SFML, but first I'd like to find what it's supposed to mean for the OS.
F10 : In Microsoft Windows activates the menu bar of an open application.
It's pretty much the same behaviour as the "ALT" key.
-
There's a task in the tracker for this issue:
https://github.com/SFML/SFML/issues/261
-
I can probably disable this special behaviour in SFML, but first I'd like to find what it's supposed to mean for the OS.
F10 : In Microsoft Windows activates the menu bar of an open application.
It's pretty much the same behaviour as the "ALT" key.
Agreed. Pressing ALT highlights or unhighlights the menu bar, and pressing F10 also highlights or unhighlights the menu bar. Laurent, if you want more reference info, here are a couple of links.
Keyboard shortcuts which mention F10:
http://support.microsoft.com/kb/126449
Reference about WM_KEYDOWN which mentions F10:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280%28v=vs.85%29.aspx