AutoHotkey Community

It is currently May 27th, 2012, 12:53 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: August 5th, 2011, 9:37 pm 
Feature Request / Bug fix:
I use an alternative keyboard layout called neo2. Every time I use the Send command, it cannot send the correct special characters.
For example:
Code:
Send, if ()
will result in "if nr", because the parenthesis lie on the n and r key of the US keyboard and get activated by pressing either capslock or # together with n/r.

Is there anything, you can do about this?

[Moderator's note: Topic split from v2 thread.]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2011, 5:41 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
AutoHotkey's standard approach is to convert each character to a key or combination of keys. Failing that, it falls back to Alt+Numpad (in ANSI builds) or the Unicode mode of SendInput(). However, some (very few, I think) keyboard layouts use non-standard shift states, such as the "Hankaku" key on Japanese keyboards and Mod3/Mod4 on the Neo layout. In v1.1.00.01 I added a check for the "Hankaku" shift state (which is Mod4 on the Neo layout) to avoid sending (the wrong) keystrokes for characters which require it. However, I didn't know additional shift states were even possible, let alone how to detect them.

I do now:
Quote:
... the high-order byte contains the shift state, which can be a combination of the following flag bits.
1 - Either SHIFT key is pressed.
2 - Either CTRL key is pressed.
4 - Either ALT key is pressed.
8 - The Hankaku key is pressed
16 - Reserved (defined by the keyboard layout driver).
32 - Reserved (defined by the keyboard layout driver).

Source: VkKeyScanEx Function

For "(" on the Neo2 layout, VkKeyScanEx returns 0x104E, which is a combination of shift state 0x10 (16) and the virtual keycode for "N". It's probably safe to say that any time these unsupported shift states (8, 16 or 32) are returned, ignoring them will give incorrect results. So I'll update the code to fall back to the Unicode mode of SendInput() when these shift states are returned. (As mentioned above, this is already done in v1.1.00.01+ for shift state 8.)

The following script can be used on any Unicode build of AutoHotkey to determine which characters use unsupported shift states:
Code:
MsgBox Switch to desired keyboard layout, then click OK.
SetFormat IntegerFast, H
Loop % 0xFFFF {
    r := DllCall("VkKeyScan", "ushort", A_Index, "short")
    if (r != -1 && (r & 0x3800))
        s .= Chr(A_Index)
}
MsgBox % s="" ? "No unsupported shift states are used by this layout." : s

With the Neo2 layout active, I get the following:
Code:
!"#$%&'()*+,./26:;<=>?@[\]_{|}~ ¡¢£¤¥¨ª¬­¯±²³µ·¹º¿×÷ſ˘˙˚˝˞ΓΔΘΛΞΠΣΦΨΩαβγδ
εζηθικλνξοπρςστυφχψωϑϕϰϱϵ᾿῾‑‘’‚†‣… ‹›⁠₀₁₂₃ℂℕ№ℚℝℤℵ←↑→↓↔↕↦↻⇌⇐⇒⇔∀∂∃∅∇∈−∘√
∝∞∡∥∧∨∩∪∫⊂⊗⊥⋅␣♀♂♣♥♦♫⚥✔✘⟨⟩

Note that "2" and "6" are shown. This is because the Neo2 keyboard layout contains more than one way to map these characters, but VkKeyScan and VkKeyScanEx can only tell us one way. According to the following blog article, which value is returned depends on the order of entries in the keyboard layout table:
If you replace 0x3800 in the code above with 0x800, it will show all characters which use Mod4/Hankaku, including "2" and "6" in the Neo layout. These characters should already work okay in v1.1.00.01+.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2011, 11:30 am 
thanks for the detailed answer, Lexikos

Until everything is working fine in a future version of AHK, I use
Code:
Send, {U+0028}
for an opening parenthesis. This works well enough for me, I use Send only in one script and there are always fixed values to send, so I don't have real issues :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2011, 2:12 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Your () example works on v1.1.02. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2011, 2:43 pm 
Wow that was fast :shock:
Everything is working fine :) great and especially fast job :wink:


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group