SFML community forums

Help => Window => Topic started by: Spaceage15 on July 25, 2010, 11:23:51 am

Title: Disabling Alt/control/shift
Post by: Spaceage15 on July 25, 2010, 11:23:51 am
Is there a way to disable these keys or pause the app when these keys are pressed. I've searched and havent really got an answer. I've seem notes saying that sfml fixed bugs for Alt/control/shift but when I hit the key, it still affects my App.

I anybody have any ideas please let me know
Title: Disabling Alt/control/shift
Post by: Nexus on July 25, 2010, 01:28:23 pm
I think you can normally handle the KeyPressed event and check if the key code is equal to one of the following:
Code: [Select]
sf::Key::LControl
sf::Key::RControl
sf::Key::LShift
sf::Key::RShift
sf::Key::LAlt
sf::Key::RAlt
Title: Disabling Alt/control/shift
Post by: Laurent on July 25, 2010, 01:36:55 pm
What do you mean with "disable these keys"? If you don't handle them in your program, nothing will happen.
Title: Disabling Alt/control/shift
Post by: Spidyy on July 25, 2010, 03:26:27 pm
If we hit the alt key, even by handling it, it make the window lose focus.

In SFML 2.0, I added this lines on the WindowImplWin32::GlobalOnEvent() function to ignore the alt key message :

Code: [Select]

if (message == WM_CLOSE)
return 0;
// Ignoring Alt key system message (Added)
if (message == WM_SYSCOMMAND && wParam == SC_KEYMENU)
return 0;


It prevent the focus lose and allow me to use the Alt key from the SFML events.
Title: Disabling Alt/control/shift
Post by: Laurent on July 25, 2010, 07:17:44 pm
That's right. But I don't know if it's wise to disable system-specific hooks. I mean, maybe some users actually use these shortcuts :)
Title: Disabling Alt/control/shift
Post by: Spidyy on July 25, 2010, 10:57:54 pm
Each game has it's own behavior with system keys.

For example, MAME allow to use Shift, Ctrl and Alt as control. It don't disable the Alt+Tab combo or other system combo.

I think it is a decision the programmer should take before the user. =p
Title: Disabling Alt/control/shift
Post by: Laurent on July 26, 2010, 09:03:56 am
I disagree, the OS global shortcuts should be consistent and always work with any app. I agree that it's often convenient to "steal" ALT for your own purpose, but think about the other shortcuts like ALT+F4, CTRL+ALT+DEL, etc.

Anyway, this is probably never going to be implemented in SFML (window.DisableAltOnWindows() ? :lol:), so...
Title: Disabling Alt/control/shift
Post by: Nexus on July 26, 2010, 01:28:14 pm
Quote from: "Spidyy"
If we hit the alt key, even by handling it, it make the window lose focus.
Is this really the case? I couldn't reproduce that behaviour on Windows 7. I think, ALT is only an issue in combination with other keys like TAB or F4.

Quote from: "Laurent"
I disagree, the OS global shortcuts should be consistent and always work with any app. I agree that it's often convenient to "steal" ALT for your own purpose, but think about the other shortcuts like ALT+F4, CTRL+ALT+DEL, etc.
In my opinion, it might be useful to "overload" ALT+F4 for the same reason we can connect the [X] (sf::Event::Closed) to a custom action, like saving data or confirming exit. With other words: Using your argumentation, SFML should also leave the default [X] functionality instead of allowing the user to customize it. A lot of games (and also other software) catch ALT+F4 and ask the user to save the program state, and I don't think this approach is fundamentally wrong.

Nevertheless, I see that it's problematic to implement the customization in a portable way, since the shortcuts are very platform-dependent.
Title: Disabling Alt/control/shift
Post by: Laurent on July 26, 2010, 02:08:04 pm
Quote
Is this really the case? I couldn't reproduce that behaviour on Windows 7. I think, ALT is only an issue in combination with other keys like TAB or F4.

Alt gives focus to the menu, and if there's no menu, it still makes something but it's not clear what :)

Quote
In my opinion, it might be useful to "overload" ALT+F4 for the same reason we can connect the [X] (sf::Event::Closed) to a custom action, like saving data or confirming exit

sf::Event::Closed is not connected to [X], it is connected to the close event of the window. Therefore, sf::Event::Closed is triggered when you hit ALT+F4 as well.

Quote
Using your argumentation, SFML should also leave the default [X] functionality instead of allowing the user to customize it

Technically this is the same thing, but in practice we both know that this feature is implemented for giving the ability to ask for saving before closing. So it's not really a way to disable or change the OS behaviour, just a way to insert custom code before finishing ;)
Title: Disabling Alt/control/shift
Post by: Beta_Ravener on July 26, 2010, 02:53:42 pm
What about sf::RenderWindow.SetFocus() ? Looks like only problem is that you loose focus to that window and jumps to menu bar (which in SFML isnt but I observed drop down menu instead). This wouldn't disable system calls, and would allow user to treat alt also. If you would like to use this invisible menu, you just wouldn't call SetFocus after pressing alt right?

Edit: Can't figure how to take control from menu to screen. Other solution would be sf::RenderWindow.EnableSystemShortcuts() maybe, which would enable/disable catching of all keys. This would leave choosing whether or not use them on programmer. At this time you are forced to use them unless you modify code as above...
Title: Disabling Alt/control/shift
Post by: Nexus on July 26, 2010, 02:59:58 pm
Quote from: "Laurent"
Alt gives focus to the menu, and if there's no menu, it still makes something but it's not clear what :)
I didn't notice before, but at a closer look, I found out that the left ALT expands the window menu (the one with minimize, move etc.), while the right ALT (ALT GR) works normally. The focus was kept in both cases (I checked the LostFocus event).

But that makes the left ALT key effectively useless on Windows, doesn't it? Even the realtime input (sf::Input::IsKeyDown()) reacts with a delay every second time.

Quote from: "Laurent"
sf::Event::Closed is not connected to [X], it is connected to the close event of the window. Therefore, sf::Event::Closed is triggered when you hit ALT+F4 as well.
Ah, very nice, I didn't know that. :)
Title: Disabling Alt/control/shift
Post by: Nexus on July 29, 2010, 07:11:27 pm
So, there is currently no way to meaningfully work with the left ALT key in a SFML application, and this will rather not change in a future release, correct?

If so, I'd probably consider the code shown by Spidyy a workaround... Or is there a better alternative (except not using ALT)? ;)
Title: Disabling Alt/control/shift
Post by: Laurent on July 29, 2010, 10:05:11 pm
Quote
So, there is currently no way to meaningfully work with the left ALT key in a SFML application, and this will rather not change in a future release, correct?

Correct.

Quote
If so, I'd probably consider the code shown by Spidyy a workaround... Or is there a better alternative (except not using ALT)?

I don't think so :?
Title: Disabling Alt/control/shift
Post by: Nexus on July 30, 2010, 03:27:03 pm
Okay, thank you.

Up to now, I have got along without ALT in my games. But when the day comes, I'll hopefully remember this thread. ;)
Title: Disabling Alt/control/shift
Post by: Tex Killer on November 01, 2011, 09:29:57 am
Hello, and I'm sorry for bringing on such old topic, but...

Over here (http://www.sfml-dev.org/forum/viewtopic.php?t=2551&sid=6a590b1d7dd55e50b71617062f88f769) you said that there was no way of using menus with only SFML (without a GUI).
Why would you want a system menu effect to be active on plain SFML?
Wouldn't it be better to left it disabled, and make a method to activate it (for future GUIs to call it)?

By the way, thanks for the time and effort.
Title: Disabling Alt/control/shift
Post by: Tex Killer on November 05, 2011, 05:20:43 pm
Is it allowed to "UP" threads around here?
Title: Disabling Alt/control/shift
Post by: Laurent on November 05, 2011, 05:31:37 pm
Yes, but I didn't understand anything about your first message :D
Title: Disabling Alt/control/shift
Post by: Tex Killer on November 06, 2011, 03:43:47 am
The matter here is that there is a system effect on Windows that affects the Alt key, and is specific to menus. Why would you want this effect active if SFML by itself doesn't allow you to use menus? Wouldn't it be better to disable the effect, and provide some function for future GUIs that may use SFML to enable it?

I'm sorry if I'm not making myself clear... As I said on another topic, english is not my main language  :?
Title: Disabling Alt/control/shift
Post by: Laurent on November 06, 2011, 09:57:53 am
Ok I got it now :P
Title: Disabling Alt/control/shift
Post by: Tex Killer on November 06, 2011, 05:24:27 pm
Does that mean you agree?  :)
Title: Disabling Alt/control/shift
Post by: Laurent on November 06, 2011, 06:48:22 pm
It means that I'll think about it in the future. Right now I have other priorities for SFML 2.0.
Title: Re: Disabling Alt/control/shift
Post by: Senzin on April 25, 2012, 08:58:43 am
I'm creating a visual graph editor. The user can drag with the mouse to create selection boxes to select nodes. Holding Shift allows the user to add to the current selection while holding Alt allows the user to subtract from the current selection. This is the same was selection works in Photoshop and many other programs with the drag-select interface. However, as others have pointed out, when you release the Alt key, the program loses focus. The user has to click on it somewhere to make it active again.

I saw someone talked about this way back in 2008 and pointed to possible solutions. However, this was the newest and first thread in the search results for this topic, so I'm posting here.
http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx