Unable to work with special keys Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Scr1pter
Posts: 1278
Joined: 06 Aug 2017, 08:21
Location: Germany

Unable to work with special keys

16 Sep 2017, 08:02

Hi guys,

I'm writing a script which copies the text of a pressed key in the clipboard and pastes it in a Notepad (e.g. Notepad++).
I was able to do this with this code (2 example keys):

Code: Select all

^+F1::	
Clipboard = Strg+Shift+F1
Send ^v
Send {Down}
return

Esc::
Clipboard = Esc
Send ^v
Send {Down}
return
I was unable to do this for 5 keys, though:
I use a German keyboard and looked how Logitech calls these keys inside of the Logitech Gaming Software:
DE key - US key
ö - Semicolon
ä - Quote
ü - LBracket
ß - Minus
´ - Equal

I read in the tutorials that it's possible to work with a Scancode instead of the key name.
Whatever I tried, it was not possible:

Code: Select all

=::
Clipboard = Test
Send ^v
Send {Down}
Return

SC192::
Clipboard = Test
Send ^v
Send {Down}
Return

; Equal:: -> says "Invalid Hotkey"
; Clipboard = Test
; Send ^v
; Send {Down}
; Return
P.S: I also tried something like &#x00D6 (e.g. for Ö), but that didn't work either

Edit
The keys are located at:
5, 6, 33, 34, 35
Image

Thanks for any help!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Unable to work with special keys

16 Sep 2017, 09:46

Hallo,
I use a German keyboard, tried this script with your 5 keys and it worked perfekt in Notepad and Notepad++.

Code: Select all

ö::
ä::
ü::
ß::
´::
Clipboard := A_ThisHotkey
Send ^v
Send {Down}
return
User avatar
Scr1pter
Posts: 1278
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Unable to work with special keys

16 Sep 2017, 12:24

Hello,

Is this your whole code?
Do you have anything addionally installed?
Because when I try this, I receive the following error when running the exe (the compiled ahk script):
Image

I also tried choosing a different bin file type (standard, ansi, unicode - always the same result)
My Ahk2Exe is v1.1.26.01

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
Scr1pter
Posts: 1278
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Unable to work with special keys  Topic is solved

16 Sep 2017, 12:37

Nevermind, problem solved!

The reason was that Notepad++ was set to UTF, when saving the AHK codes.
After changing it to ANSI, it worked.

Is it generally better to have ANSI selected?
I also create lua scripts which get used by the Logitech Gaming Software.

Best regards - Viele Grüße ;)
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Unable to work with special keys

16 Sep 2017, 13:07

Hi, Scr1pter
Is it generally better to have ANSI selected?
As I know, Notepad++ creates (and saves) files by default with UTF-8 without BOM. To recognize a file code page AHK needs files saved to UTF-8 with BOM.
If file is saved to ANSI, you may lose non-ANSI symbols, if they present.
User avatar
Scr1pter
Posts: 1278
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Unable to work with special keys

16 Sep 2017, 16:38

Thanks again for your help, guys.

May I ask something else?
I'm trying to make the script be active only in Notepad++.
I read in the tutorials and used the function GetClass to find out Notepad++'s class.

Code: Select all

^+F1::
WinGetClass, class, A
MsgBox, Class of current window is "%class%".
The compiled script says that the class is named Notepad++

Now I added in my "key to text -script" this line:

Code: Select all

#SingleInstance ignore
if WinActive("ahk_class Notepad++")
^+F11::	
Clipboard = Strg+Shift+F11
Send ^v
Send {Down}
return

^+F10::	
Clipboard = Strg+Shift+F10
Send ^v
Send {Down}
return

^+F1::	
Clipboard = Strg+Shift+F1
Send ^v
Send {Down}
return

Esc::
Clipboard = Esc
Send ^v
Send {Down}
return
I thought it work now only work when Notepad++ is active, but the script works always.
Probably I have missed something?
I also added a { right after the if line and a } at the end of the code - didn't work either...

Thanks again!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Unable to work with special keys

17 Sep 2017, 00:51

Hallo,
du hast wirklich eine Kleinigkeit vergessen! Die 2.Zeile sollte heißen:

Code: Select all

#if WinActive("ahk_class Notepad++")
siehe http://ahkde.github.io/docs/commands/_IfWinActive.htm
User avatar
Scr1pter
Posts: 1278
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Unable to work with special keys

17 Sep 2017, 09:10

Super, danke!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 323 guests