BrewManNH Posted August 16, 2014 Share Posted August 16, 2014 US English keyboard L-CTRL = 11 A2 R-CTRL = 11 A3 L-ALT = 12 A4 R-ALT = 12 A5 Pressing them in any combination always results in a combination of the above codes. For example, Right Alt and L-CTRL = 11 12 A2 A5. It doesn't matter in which sequence you press the keys, left first, right first, alt first, or ctrl first, the results are always a combination of the scan codes above. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Exit Posted August 16, 2014 Share Posted August 16, 2014 @BrewManNH And the R-Alt on your US English keyboard is labelled Alt or AltGr ? App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
BrewManNH Posted August 16, 2014 Share Posted August 16, 2014 As stated several times above, it's marked ALT, there is no AltGr key on a US keyboard. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Zohar Posted August 16, 2014 Author Share Posted August 16, 2014 (edited) Alone: RAlt: 12 A5 RCtrl: 11 A3 LAlt: 12 A4 LCtrl: 11 A2 Together: RAlt+RCtrl: 11 12 A3 A5 LAlt+LCtrl: 11 12 A2 A4 No difference if Ctrl or Alt was first. Edited August 16, 2014 by Zohar Link to comment Share on other sites More sharing options...
Exit Posted August 17, 2014 Share Posted August 17, 2014 @Zohar Found a potential case of your problem. You have 2 keyboards defined in your system. LALT+SHIFT is the default key to switch between those keyboards. I added a US keyboard and verified the case. Just run my script and see the key codes of RALT when switching by LALT+SHIFT. Solution: Remove the second keyboard in system settings. LALT+SHIFT will never hit you by accident. Zohar 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Zohar Posted August 17, 2014 Author Share Posted August 17, 2014 (edited) Exit, it seems that you are a genius I do have 2 Input Languages installed (but not by mistake - I am using both) I tested what you wrote now, and it is exactly as you said. When my keyboard is on English, there's no problem. When I switch language via Alt+Shift, suddenly the problem happens, and now it's 100% of the time! It only stops when I resume back to English. You are amazing. I really thank you and everyone in this thread for advancing finding the cause of the problem. Now regarding a solution: Since I need 2 languages, I cannot delete 1, to prevent Alt-Shift from changing mode. What else might I do to solve it? The problem is that when I switch to Language2, then pressing RAlt-[someKey] works as if I pressed Ctrl-Alt-[someKey].. which is a totally different HotKeySet handler.. Edited August 17, 2014 by Zohar Link to comment Share on other sites More sharing options...
Exit Posted August 17, 2014 Share Posted August 17, 2014 @Zohar What is the second language? Just set the keyboard of the second language to US. Or need you some special characters of this language? At least, you can set another hotkey for switching the language. E.g. LCNTL+NUMPADMINUS. This cannot be pressed accidentally. Btw. I made a hex key code display script for all keys. ;~ WhatKeyispressed.au3 Author: Exit #include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hDLL = DllOpen("user32.dll") GUICreate("Press any key(s) to show hex key codes ", 315, 315, -1, -1, Default, $WS_EX_TOPMOST) Local $a[16][16] For $y = 0 To 15 For $x = 0 To 15 $a[$y][$x] = GUICtrlCreateLabel(Hex($y * 16 + $x, 2), $x * 20, $y * 20, -1, -1) GUICtrlSetState($a[$y][$x], $GUI_HIDE) Next Next $keydump = GUICtrlCreateEdit("", -50, 0, 0, 0) ; Out of windows boundary. Will accept keystrokes. GUISetState(@SW_SHOW) While True If _IsPressed("1B", $hDLL) Then ExitLoop If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop For $y = 0 To 15 For $x = 0 To 15 GUICtrlSetState($a[$y][$x], (_IsPressed(Hex($y * 16 + $x, 2), $hDLL) ? $GUI_Show : $GUI_HIDE)) Next Next WEnd DllClose($hDLL) Please test it in your environment. Thanks. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Zohar Posted August 17, 2014 Author Share Posted August 17, 2014 (edited) What is the second language? L1 = English L2 = Hebrew Just set the keyboard of the second language to US. In my humble opinion, it does not have to do with the Language chosen, but with the fact that you have more than 1 Input Language. Because once you have more than 1 Input Language, then it's possible to switch between them, and it seems that it is a small bug in Windows, in which when you're in L2 (or more generally when you're not in L1), then the behavior of the Right Alt changes. (I will verify this) At least, you can set another hotkey for switching the language. E.g. LCNTL+NUMPADMINUS. This cannot be pressed accidentally. The thing is that I need to switch between the languages. So I cannot delete L2.. Btw. I made a hex key code display script for all keys. ;~ WhatKeyispressed.au3 Author: Exit #include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hDLL = DllOpen("user32.dll") GUICreate("Press any key(s) to show hex key codes ", 315, 315, -1, -1, Default, $WS_EX_TOPMOST) Local $a[16][16] For $y = 0 To 15 For $x = 0 To 15 $a[$y][$x] = GUICtrlCreateLabel(Hex($y * 16 + $x, 2), $x * 20, $y * 20, -1, -1) GUICtrlSetState($a[$y][$x], $GUI_HIDE) Next Next $keydump = GUICtrlCreateEdit("", -50, 0, 0, 0) ; Out of windows boundary. Will accept keystrokes. GUISetState(@SW_SHOW) While True If _IsPressed("1B", $hDLL) Then ExitLoop If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop For $y = 0 To 15 For $x = 0 To 15 GUICtrlSetState($a[$y][$x], (_IsPressed(Hex($y * 16 + $x, 2), $hDLL) ? $GUI_Show : $GUI_HIDE)) Next Next WEnd DllClose($hDLL) Please test it in your environment. Thanks. On which keys should I test it? Edited August 17, 2014 by Zohar Link to comment Share on other sites More sharing options...
Exit Posted August 17, 2014 Share Posted August 17, 2014 (edited) In my humble opinion, it does not have to do with the Language chosen, but with the fact that you have more than 1 Input Language. Because once you have more than 1 Input Language, then it's possible to switch between them, and it seems that it is a small bug in Windows, in which when you're in L2 (or more generally when you're not in L1), then the behavior of the Right Alt changes. No. it depends on the chosen keyboard. US keyboard has no AltGr functionality, only ALT. Codes: 12 A5 US keyboard (international) has AltGr functionality. Codes: 11 12 A2 A5 Same with German and Hebrew keyboards. Most keyboards have AltGr. Only old US keyboard has no AltGr. See my pointer to the Wikipedia link in post #5 Just choose US (international) keyboard and you get rid of the differences. It is more convenient to press only one key for getting all the special characters which need CNTL and ALT pressed. But it is a learning curve. Some people like the old fashioned way. The thing is that I need to switch between the languages. If you insist in using the right ALT key the old fashioned way, then you should at least disable the LALT+LSHIFT key. For switching the language, I would propose the hotkeys CNTL+SHIFT+1 and CNTL+SHIFT+2. Then there is only a minor chance to switch accidentally. And to solve your hotkey setting problem, I have prepared a small skeleton. #include <misc.au3> _HotKey("{ESC}") ; Exit script _HotKey("!{-}") ; Alt + minus _HotKey("^!{-}") ; AltGr + minus or Cntl + Alt + minus Func _HotKey($hotkey = "") Switch @HotKeyPressed Case "{ESC}" Exit MsgBox(64 + 262144, Default, "Exit", 3) Case "!{-}" _Handle_ALT_Minus() Case "^!{-}" If _IsPressed("A5") and (Not _IsPressed("A3")) Then _Handle_ALT_Minus() Else _Handle_CNTL_ALT_Minus() EndIf Case Else If Not IsDeclared("hotkey") Then Return MsgBox(16 + 262144, Default, "No CASE statement defined for hotkey " & @HotKeyPressed) If HotKeySet($hotkey, "_Hotkey") = 0 Then Return MsgBox(16 + 262144, Default, "Hotkey " & $hotkey & " invalid or set by another application.") EndSwitch EndFunc ;==>_HotKey While Sleep(100) ; here should be your application. WEnd ; meanwhile, here is a dummy loop. Func _Handle_ALT_Minus() ;~ RALT and LCNTL+RALT have the same hex codes. So it is assumed to be RALT only. MsgBox(64 + 262144, Default, "Alt + minus pressed"&@lf&@lf&@lf&@lf&@lf&"or LCNTL+RALT. Cannot be distinguished.", 5) EndFunc ;==>_Handle_ALT_Minus Func _Handle_CNTL_ALT_Minus() MsgBox(64 + 262144, Default, "Cntl + Alt + minus pressed", 5) EndFunc ;==>_Handle_CNTL_ALT_Minus Since there is no difference between RALT and LCNTL+RALT, it is assumed to be RALT only. Hope this helps. Edit: And here a screenshot to show setting of hotkeys for languages. Sorry to give only a German screenshot No English system available. Edited August 17, 2014 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
BrewManNH Posted August 17, 2014 Share Posted August 17, 2014 I beg to differ on the Old US Keyboard comment, every keyboard that I've ever seen sold, or delivered with a new computer, up to the present time still has no AltGr key. In the US there's no need for something like that, in fact the AltGr key is actually a very old keyboard key, and was eliminated in the US years ago, while the rest of the world hasn't caught up yet. Only US International keyboards have the key, and that keyboard is practically non-existent in the US itself. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Zohar Posted August 18, 2014 Author Share Posted August 18, 2014 (edited) No. it depends on the chosen keyboard. US keyboard has no AltGr functionality, only ALT. Codes: 12 A5 US keyboard (international) has AltGr functionality. Codes: 11 12 A2 A5 Same with German and Hebrew keyboards. Most keyboards have AltGr. Only old US keyboard has no AltGr. See my pointer to the Wikipedia link in post #5 Wow, so it's not whether you're on L1 or L2, but it depends on how the keyboard's keys are defined in Windows.. Interesting. And to solve your hotkey setting problem, I have prepared a small skeleton. #include <misc.au3> _HotKey("{ESC}") ; Exit script _HotKey("!{-}") ; Alt + minus _HotKey("^!{-}") ; AltGr + minus or Cntl + Alt + minus Func _HotKey($hotkey = "") Switch @HotKeyPressed Case "{ESC}" Exit MsgBox(64 + 262144, Default, "Exit", 3) Case "!{-}" _Handle_ALT_Minus() Case "^!{-}" If _IsPressed("A5") and (Not _IsPressed("A3")) Then _Handle_ALT_Minus() Else _Handle_CNTL_ALT_Minus() EndIf Case Else If Not IsDeclared("hotkey") Then Return MsgBox(16 + 262144, Default, "No CASE statement defined for hotkey " & @HotKeyPressed) If HotKeySet($hotkey, "_Hotkey") = 0 Then Return MsgBox(16 + 262144, Default, "Hotkey " & $hotkey & " invalid or set by another application.") EndSwitch EndFunc ;==>_HotKey While Sleep(100) ; here should be your application. WEnd ; meanwhile, here is a dummy loop. Func _Handle_ALT_Minus() ;~ RALT and LCNTL+RALT have the same hex codes. So it is assumed to be RALT only. MsgBox(64 + 262144, Default, "Alt + minus pressed"&@lf&@lf&@lf&@lf&@lf&"or LCNTL+RALT. Cannot be distinguished.", 5) EndFunc ;==>_Handle_ALT_Minus Func _Handle_CNTL_ALT_Minus() MsgBox(64 + 262144, Default, "Cntl + Alt + minus pressed", 5) EndFunc ;==>_Handle_CNTL_ALT_Minus Since there is no difference between RALT and LCNTL+RALT, it is assumed to be RALT only. Hope this helps. This is a really cool workaround, I will use it - thank you very much. I am curious: could we also fix the problem not on AutoIt's level, but on Windows level? For example, If we added a Language that has the AltGr key, can we tell Windows to change the behavior of a specific key for an Input Language? (via some place in Windows, and not via an AutoIt code..) Edit: And here a screenshot to show setting of hotkeys for languages. Sorry to give only a German screenshot No English system available. Umm, why is changing the way I switch between the languages can help? In my case I said I need to switch between the languages, and I stay sometime on one launguage or the other due to a need, so it's not that I switch by mistake.. Only US International keyboards have the key, and that keyboard is practically non-existent in the US itself. Same here. I am not sure when is the last time I saw a keyboard with the Right Alt key labelled as "AltGr". Edited August 18, 2014 by Zohar Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now