TrimClipboard works fine in English mode but deletes text in Hebrew mode

Get help with using AutoHotkey and its commands and hotkeys
benqzq
Posts: 6
Joined: 30 May 2017, 07:53

TrimClipboard works fine in English mode but deletes text in Hebrew mode

30 May 2017, 08:35

Hello, I am very new to programming and just recently discovered AutoHotkey. I have yet to find free time to study it's basics in the needed depth and have a problem running the following code in Win10 Hebrew mode.

The following code uuses me to copy text to clipboard but to also trim all leads (tabulations and spaces alike) from that text, before it reached the clipboard (I assume AutoHotkey copies the code to some medium in the memory, trims its leads, and then re-copies it to clipboard but I might be wrong and the trimming is done after it reached the clipboard).

With this code, if I paste text in a indentoophobic environment like GNU Bash, the text will be pasted unindented, and will be more executable.

My code:

Code: Select all

TrimClipboard() {
linesArray := StrSplit(clipboard, "`n", "`r")

newClip := ""

for index, element in linesArray {
newClip .= trim(element) . "`r`n"
}

clipboard := SubStr(newClip, 1, -2)
}

#IfWinActive ahk_class Notepad++
^c::
Send, ^c
Clipwait
TrimClipboard()
return

+^x::
Send, ^x
Clipwait
TrimClipboard()
return

#IfWinActive
My problem:

When I use the script when Windows10 is in English, it works fine, but when I use it when Windows is in Hebrew, text I copy is actually being deleted and I need to undo the copying to retrieve it.

To prevent this I tried:

1. if !LangID := EN { return }.

2. Wrapping the whole script with a similar version of if !LangID := EN so before anything, the script will check if the current Win10 language isn't English.

3. Wrapping content inside TrimClipboard() with a relevant else statement:

Code: Select all

TrimClipboard() {
if LangID := EN {
linesArray := StrSplit(clipboard, "`n", "`r")

newClip := ""

for index, element in linesArray {
newClip .= trim(element) . "`r`n"
}

clipboard := SubStr(newClip, 1, -2)
}

else {return}
}
All 3 tries resulted with an error.

My desired situation:

My desired situation is that the code will work regularly when Win10 is in Hebrew mode as well (or in any other language besides English, for that matter).
Last edited by benqzq on 03 Jun 2017, 23:07, edited 4 times in total.
BoBo
Posts: 4107
Joined: 13 May 2014, 17:15

Re: TrimClipboard works fine in English mode but deletes text in Hebrew mode

30 May 2017, 10:41

That topic is way above my head and that specific issue might have gone away with AHK 1.1.x ...
Nevertheless ... something to read until the pro-bro's are showing up :)

https://www.google.de/search?q=site%3Aa ... com+hebrew
https://autohotkey.com/board/topic/5205 ... clipboard/
benqzq
Posts: 6
Joined: 30 May 2017, 07:53

Re: TrimClipboard works fine in English mode but deletes text in Hebrew mode

31 May 2017, 06:11

Code: Select all

TrimClipboard()
{
if (LangID = "EN") {

Contents 

} else {return}
}
Brings error...
Guest

Re: TrimClipboard works fine in English mode but deletes text in Hebrew mode

31 May 2017, 06:40

Ok that's helpful. :D

1. It is Return not {return}
2. As I see it LangID isn't global (perhaps you have defined it so elsewhere in your script) so you may need to pass it on the function as parameter OR make it global - see local & global variables https://autohotkey.com/docs/Functions.htm#Locals
3. What kind of error message do you get.
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: TrimClipboard works fine in English mode but deletes text in Hebrew mode

31 May 2017, 20:36

Make sure you have a Unicode version of AutoHotkey installed.
benqzq
Posts: 6
Joined: 30 May 2017, 07:53

Re: TrimClipboard works fine in English mode but deletes text in Hebrew mode

01 Jun 2017, 09:20

Guest, I get various error messages in each change. I don't have the spare time to publish each one here. Sorry. I will try making LangID global though (and no, I didn't defined it somewhere else in the script).
benqzq
Posts: 6
Joined: 30 May 2017, 07:53

Re: TrimClipboard works fine in English mode but deletes text in Hebrew mode

01 Jun 2017, 09:27

lexikos, my current version is 1.1.25.02. It is indeed Unicode, for 64 bit Windows.
benqzq
Posts: 6
Joined: 30 May 2017, 07:53

Re: TrimClipboard works fine in English mode but deletes text in Hebrew mode

09 Jun 2017, 21:13

The AHk programmer Eugene Kartoyev shared with me his solution to the problem on Facebook. I asked him to reply here but for any case I publish his answer so people could reach it from Google:
I've noted local kbd layouts are not quite working if you try something like Crtl+C because "C" corresponds to some other letter in a foreign layout.

I use scancodes for those cases. I don't know TrimClipboard, but you may need to reprogram it, to make it SendInput, ^{sc02e} instead of SendInput, ^c -- or something, where sc02e corresponds to the KEY "C" irrespective of the layout.
This seems to have worked like a charm.

Eugene also shared this table that can help supply different ASCII key codes, per mode:

Image

This and similar tables can be found in Google (and especially Google images) with the search phrase scancodes table.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], DaveT1, Google [Bot], HeroOfKvatch, HiSoKa, JKnight_xbt33, just me, mad3d and 70 guests