leuce Posted June 21, 2017 Posted June 21, 2017 G'day everyone Long ago (2013), while using Windows XP still, I wrote a little script with shortcuts for typing hard-to-type characters. For example, Ctrl+) types a curly apostrophe. However, after switching to Windows 7, I discovered that the script no longer pastes the correct characters. Instead, it pastes the Unicode character U+FFFD ("replacement character"). It took me a while to notice this, because I was using an EXE version of the script, and the EXE version (which was compiled on Windows XP) functions correctly. If I compile a new EXE on Windows 7, it doesn't paste the correct characters either. Can anyone please have a look at the script and tell me what should change for this to work in Windows 7 (and hopefully also later versions of Windows)? As it is, I can't add new features due to this problem. expandcollapse popup#Include <String.au3> $nonbreaker = _HexToString("a0") $dasher = _HexToString("96") $dotter = _HexToString("85") $singleopenquote = _HexToString("91") $singleclosequote = _HexToString("92") $doubleopenquote = _HexToString("93") $doubleclosequote = _HexToString("94") MsgBox (0, "Seven keyboard shortcuts for Idiom translators, version 4", "Shift+Ctrl+Space = non-breaking space (e.g. between digits and SI symbols, ""5 cm"")" & @CRLF & "Alt+Ctrl+fullstop = ellips (...)" & @CRLF & "Ctrl+NumMinus = en-dash" & @CRLF & "and also Ctrl+hyphen = en-dash" & @CRLF & @CRLF & "Ctrl+( = single opening quote" & @CRLF & "Ctrl+) = single closing quote (or curly apostrophe)" & @CRLF & "Ctrl+Shift+( = double opening quote" & @CRLF & "Ctrl+Shift+) = double closing quote" & @CRLF & @CRLF & "Some shortcuts may not work in a browser text field." & @CRLF & @CRLF & "To exit the program or to disable the shortcuts, click the round blue icon in the system tray.", 0) HotKeySet("+^{SPACE}", "nonbreakspace") HotKeySet("^{NUMPADSUB}", "endash") HotKeySet("^-", "hyphdash") HotKeySet("!^.", "ellips") HotKeySet("^9", "singleopen") HotKeySet("^0", "singleclose") HotKeySet("^+9", "doubleopen") HotKeySet("^+0", "doubleclose") While 1 Sleep(100) WEnd Func nonbreakspace() ClipPut ($nonbreaker) Send ("^v") EndFunc Func endash() ClipPut ($dasher) Send ("^v") EndFunc Func hyphdash() ClipPut ($dasher) Send ("^v") EndFunc Func ellips() ClipPut ($dotter) Send ("^v") EndFunc Func singleopen() ClipPut ($singleopenquote) Send ("^v") EndFunc Func singleclose() ClipPut ($singleclosequote) Send ("^v") EndFunc Func doubleopen() ClipPut ($doubleopenquote) Send ("^v") EndFunc Func doubleclose() ClipPut ($doubleclosequote) Send ("^v") EndFunc Thanks! Samuel
water Posted June 21, 2017 Posted June 21, 2017 Here it works without any problem from SciTE and compiled. Environment: Windows 7 Enterprise AutoIt 3.3.14.2 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
leuce Posted June 21, 2017 Author Posted June 21, 2017 That's unfortunate. A complete fresh re-install of AutoIt did not solve the problem. It looks like I'm going to have to find another way to put the appropriate content on the clipboard or to send the relevant character.
water Posted June 21, 2017 Posted June 21, 2017 You need to add some error checking to your script. Each function provides a return value or sets @error - which might tell you what goes wrong. BTW: Which Version of AutoIt do you run today? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted June 21, 2017 Posted June 21, 2017 (edited) Seems the problem is caused by some combinations of keys get consumed by Windows or deliver an unexpected result: Shift+Alt changes the keyboard layout to another language (e.g. switches from German to English to German). The third character of the hotkey then might be a completely different character then intended. Shift sends upper case characters. In case of special characters this might be a completely different character: Shift+. get's sent as Shift+: (German keyboard). As described in the help file "It is recommended to use lower-case keys/characters (e.g. "b" and not "B") when setting hotkeys to avoid errors as with some keyboard layouts upper and lower case keys may be mapped differently." So I suggest you avoid Shift and Shift+Alt in your Hotkey settings. Edit: Windows Shortcuts Edited June 21, 2017 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
leuce Posted June 21, 2017 Author Posted June 21, 2017 (edited) 1. I'm using 3.3.14.2 on Windows 7 HP. 2. I must confess I don't quite know how to use @error. Is there a page or something that explains it? I sometimes use it but I can't rely on it because I'm not sure I use it properly. 3. Shift+Alt etc. changes the keyboard language/layout and/or the screen rotation only if those shortcuts are enabled in Windows itself. They are disabled here. 4. The comment about using "b" instead of "B" is already taken into account. For example, I tell the user to press Shift + Ctrl + (, but in reality the hotkey is for ^+9, because on our keyboards the "(" is on the same key as the 9. In the same way, if a shortcut that I use is ^b, then I tell the user that it's Ctrl + B because that's easier to read, even though it is actually Ctrl + b. Edited June 21, 2017 by leuce
water Posted June 21, 2017 Posted June 21, 2017 Me too It depends on the function you call. Some set the return value, some set the @error macro. The help file exactly explains what to expect from a function. The function of the keys might be disabled. But are you sure that the keys aren't still consumed by Windows so that they don't get sent to your script? You can still confuse your script: Setting "!^." does not work as there is no way to press "." after "shift" has been pressed as then you get ":". POC: HotKeySet("{Esc}", "_exit") ; End Skript HotKeySet("+.", "_Test_Dot") ; Shift+. HotKeySet("+:", "_Test_Colon") ; Shift+: While 1 Sleep(100) WEnd Func _Test_Dot() ConsoleWrite("Function _Test_Dot called!" & @CRLF) EndFunc ;==>_test_Dot Func _Test_Colon() ConsoleWrite("Function _Test_Colon called!" & @CRLF) EndFunc ;==>_test_Colon Func _exit() Exit EndFunc ;==>_exit My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
leuce Posted June 21, 2017 Author Posted June 21, 2017 3. The EXE version's shortcut keys work just fine. And I've tested the shortcuts separately in a test script -- none of them are used by Windows when a script is running. 4. I assume "." and ":" are on the same key on your keyboard (German keyboard, right?). Yes, you're right, but then, I never use just Shift + something as a shortcut :-) That's looking for trouble.
anthonyjr2 Posted June 21, 2017 Posted June 21, 2017 While it is a slightly different approach than how you did it, this way works and doesn't require any conversion of hex. expandcollapse popup#Include <String.au3> MsgBox (0, "Seven keyboard shortcuts for Idiom translators, version 4", "Shift+Ctrl+Space = non-breaking space (e.g. between digits and SI symbols, ""5 cm"")" & @CRLF & "Alt+Ctrl+fullstop = ellips (...)" & @CRLF & "Ctrl+NumMinus = en-dash" & @CRLF & "and also Ctrl+hyphen = en-dash" & @CRLF & @CRLF & "Ctrl+( = single opening quote" & @CRLF & "Ctrl+) = single closing quote (or curly apostrophe)" & @CRLF & "Ctrl+Shift+( = double opening quote" & @CRLF & "Ctrl+Shift+) = double closing quote" & @CRLF & @CRLF & "Some shortcuts may not work in a browser text field." & @CRLF & @CRLF & "To exit the program or to disable the shortcuts, click the round blue icon in the system tray.", 0) HotKeySet("+^{SPACE}", "nonbreakspace") HotKeySet("^{NUMPADSUB}", "endash") HotKeySet("^-", "hyphdash") HotKeySet("!^.", "ellips") HotKeySet("^9", "singleopen") HotKeySet("^0", "singleclose") HotKeySet("^+9", "doubleopen") HotKeySet("^+0", "doubleclose") While 1 Sleep(100) WEnd Func nonbreakspace() Send (" ",1) EndFunc Func endash() Send ("–",1) EndFunc Func hyphdash() Send ("-",1) EndFunc Func ellips() Send ("…",1) EndFunc Func singleopen() Send ("‘",1) EndFunc Func singleclose() Send ("’",1) EndFunc Func doubleopen() Send ("“",1) EndFunc Func doubleclose() Send ("”",1) EndFunc I just put each alt code into the send and sent it raw. From my testing it seems to work just as well. UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=
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