Skip to content

Commit

Permalink
Disable current modifiers when using the GTK+ or Office workarounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
samhocevar committed Mar 2, 2015
1 parent a3157bc commit 108898c
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions src/composer/Composer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public static bool OnKey(WM ev, VK vk, SC sc, LLKHF flags)

private static void SendString(string str)
{
List<VK> modifiers = new List<VK>();
bool is_gtk = false, is_office = false;

const int len = 256;
Expand All @@ -158,10 +159,29 @@ private static void SendString(string str)
is_office = true;
}

/* Clear keyboard modifiers if we need one of our custom hacks */
if (is_gtk || is_office)
{
VK[] all_modifiers = new VK[]
{
VK.LSHIFT, VK.RSHIFT,
VK.LCONTROL, VK.RCONTROL,
VK.LMENU, VK.RMENU,
};

foreach (VK vk in all_modifiers)
if ((NativeMethods.GetKeyState(vk) & 0x80) == 0x80)
modifiers.Add(vk);

foreach (VK vk in modifiers)
SendKeyUp(vk);
}

if (is_gtk)
{
/* Wikipedia says Ctrl+Shift+u, release, then type the four hex digits, and
* press Enter (http://en.wikipedia.org/wiki/Unicode_input). */
/* Wikipedia says Ctrl+Shift+u, release, then type the four hex
* digits, and press Enter.
* (http://en.wikipedia.org/wiki/Unicode_input). */
SendKeyDown(VK.LCONTROL);
SendKeyDown(VK.LSHIFT);
SendKeyPress((VK)'U');
Expand Down Expand Up @@ -196,19 +216,40 @@ private static void SendString(string str)
NativeMethods.SendInput((uint)input.Count, input.ToArray(),
Marshal.SizeOf(typeof(INPUT)));
}

/* Restore keyboard modifiers if we needed one of our custom hacks */
if (is_gtk || is_office)
{
foreach (VK vk in modifiers)
SendKeyDown(vk);
}
}

public static bool IsComposing()
{
return m_composing;
}

private static INPUT NewInputKey(object o)
private static INPUT NewInputKey(VirtualKeyShort vk)
{
INPUT ret = NewInputKey();
ret.U.ki.wVk = vk;
return ret;
}

private static INPUT NewInputKey(ScanCodeShort sc)
{
INPUT ret = NewInputKey();
ret.U.ki.wScan = sc;
return ret;
}

private static INPUT NewInputKey()
{
INPUT ret = new INPUT();
ret.type = EINPUT.KEYBOARD;
ret.U.ki.wVk = (VirtualKeyShort)(o is VirtualKeyShort ? o : 0);
ret.U.ki.wScan = (ScanCodeShort)(o is ScanCodeShort ? o : 0);
ret.U.ki.wVk = (VirtualKeyShort)0;
ret.U.ki.wScan = (ScanCodeShort)0;
ret.U.ki.time = 0;
ret.U.ki.dwFlags = KEYEVENTF.UNICODE;
ret.U.ki.dwExtraInfo = UIntPtr.Zero;
Expand Down

0 comments on commit 108898c

Please sign in to comment.