Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Keyboard layout independent Send method (KEYEVENTF_UNICODE)


  • Please log in to reply
2 replies to this topic
Mircode
  • Guests
  • Last active:
  • Joined: --
Hi!

This:
http://www.autohotke...topic72249.html
is my problem.

I had contact with someone from the neo project. He said, that maybe AHK searches the current keyboard layout and then simulates the corresponding keystrokes. While this may work normally, it confuses the unconventional layers of the neo layout.

Since AHK has no problems, if the desired symbol does not appear on the current kbd layout at all, I assume that it uses a different method then.

As mentioned in the other post, i wrote my own hotstring replace program once. It always uses SendInput with KEYEVENTF_UNICODE and has no problems with the neo layout. And I assume, that AHK does the same if the symbol is not on the current keyboard layout.

I would like to propose a new send method or flag, so that KEYEVENTF_UNICODE is always used.

Please let me know if this request is accepted and if so, how long it would take to implement it. Otherwise I will try to write a dll which sends a string via SendInput and KEYEVENTF_UNICODE.

Thanks in advance!
Mirko

Mircode
  • Guests
  • Last active:
  • Joined: --
I did it myself.

Here are the changes in AHK_L's source code:

Only the SendKeys function in keyboard_mouse.cpp had to be modified slightly.

	int repeat_count, click_x, click_y;
	bool move_offset, key_down_is_persistent;
	bool uni_mode=false; ///////////////// <- new variable
	DWORD placeholder;

	...

	else if (!_tcsnicmp(aKeys, _T("Raw"), 3)) // This is used by auto-replace hotstrings too.
	{
		// As documented, there's no way to switch back to non-raw mode afterward since there's no
		// correct way to support special (non-literal) strings such as {Raw Off} while in raw mode.
		aSendRaw = true;
		goto brace_case_end; // This {} item completely handled, so move on to next.
	}
	///////////////// new item /////////////////
	else if (!_tcsnicmp(aKeys, _T("Uni"), 3)) // Always use the special send method after this item
	{
		uni_mode = true;
		goto brace_case_end; // This {} item completely handled, so move on to next.
	}
	///////////////// end of new item /////////////////

	...

	else // Encountered a character other than ^+!#{} ... or we're in raw mode.
	{
		// Best to call this separately, rather than as first arg in SendKey, since it changes the
		// value of modifiers and the updated value is *not* guaranteed to be passed.
		// In other words, SendKey(TextToVK(...), modifiers, ...) would often send the old
		// value for modifiers.
		single_char_string[0] = *aKeys; // String was pre-terminated earlier.
																				   ///////////////// new condition "&& !uni_mode"
		if (vk = TextToVK(single_char_string, &mods_for_next_key, true, true, sTargetKeybdLayout) && !uni_mode)
			// TextToVK() takes no measurable time compared to the amount of time SendKey takes.
			SendKey(vk, 0, mods_for_next_key, persistent_modifiers_for_this_SendKeys, 1, KEYDOWNANDUP
				, 0, aTargetWindow);
		else // Try to send it by alternate means.
		{ ...

This introduces the {Uni} element. It can be used just like {Raw} and causes everything after it to be sent via KEYEVENTF_UNICODE, if possible.

Mircode
  • Guests
  • Last active:
  • Joined: --
Sometimes it wont work. Im tired of this. I will use my old program again.