Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How do I mimick EXACTLY PHYSICAL keystrokes?


  • Please log in to reply
4 replies to this topic
ahkgzb
  • Members
  • 6 posts
  • Last active: Feb 21 2007 06:54 PM
  • Joined: 21 Feb 2007
I appologize up front if this questions sounds naive or even plain stupid. I am basically a newbie to AHK - I only started using it today with great hopes that it would automate my repetitive typing.

For simple and trivial stuff it works great!

But when I try to use some of the more sophisticated features of Windows (2000/XP) it simply decides for me how to actually interpret "the keystrokes"...

Case in question: when I try to type a special character that requires the following key sequence:

1. Press & Release Caps Lock (Caps Lock LED should now be on)
2. Press Shift - and hold it down
3. Press & release the key 4 (top keyboard row, with the $ sign on top of it).
4. Release Shift

When I do that physically, everything works fine: It should generate a special character in the language input mode I am in - not '4' or '$'.

However, when I try to mimick this in AHK - no matter what method I use (Send, SendInput, {Raw}, etc. - I keep getting either 4 or $ - instead of the desired special character.

For example, I tried the following key sequence too (with and without {Raw}:

SendInput {Shift Down}{Raw}4
SendInput {Shift Up}
To no avail.

Why can't AHK simply play back my keystrokes? That is, as if I typed them myself, pressing physically on the keys?

Or can it?

If so, how?

Thanks a Million!
Gabby

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Have you tried simply putting the special character into the Send?

Also, open up the Key History of a running script and type the character to see if it has a unique key code. If so, it's being handled by the keyboard itself and not the software that AHK sends to.

ahkgzb
  • Members
  • 6 posts
  • Last active: Feb 21 2007 06:54 PM
  • Joined: 21 Feb 2007

Have you tried simply putting the special character into the Send?


Yes I did - AHK keeps translating it to to the '$' character.
This is a printable character so I can clearly see it in Notepad when editing and saving the AHK script. So I know it must be AHK that introduces yet another level of translation here.

Also, open up the Key History of a running script and type the character to see if it has a unique key code. If so, it's being handled by the keyboard itself and not the software that AHK sends to.


I opened the Key History (not sure how to type it so that i can be displayed - I think some hook or something needs to be present) - and I can see that character displayed in the Key History - as provided in the script.

Isn't there a mode in AHK that says "playback those keystrokes as if they were phsyical keys"?

Thanks!
Gabby

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004

I opened the Key History (not sure how to type it so that i can be displayed - I think some hook or something needs to be present) - and I can see that character displayed in the Key History - as provided in the script.


Aha, here's the problem. By the time it gets to the rest of the OS, it's already been translated into the special character. To illustrate why this is a problem, I'll first answer your other question... playing back "physical keystrokes."

AutoHotkey, as a program itself, can't actually type the keys. What it does is perform functions that are somewhat like the end result of pressing a key, such as sending a key-press "event" to a window. Most programs can't tell the difference between that and an actual key press. However, if Windows deals with a certain key combination on a very low-level basis, or if the keyboard itself does (e.g. some programmable keyboards), then that key combination won't be the same as what AutoHotkey sends, since it bypasses all that. One example of this is Ctrl-Alt-Delete. Even if you "disable" it with AutoHotkey, Windows will still be able to catch it, since it wisely implements that functionality at a level too low for any program to access.

I do have one more suggestion, however. Since it shows up as a single character in the Key History, you may be able to use the key code to send it. Open up the Key History again and note the key's VK and SC codes (the first two columns on the left). You can use those to send it like this:
Send {vk45sc123}


ahkgzb
  • Members
  • 6 posts
  • Last active: Feb 21 2007 06:54 PM
  • Joined: 21 Feb 2007
Thanks, jonny.

Your last suggestion is most likely to work on my computer, but the script I am writing should work on another computer - that has a different keyboard.

So... I found a workaround - that actually works for any computer: since the keystrokes I am trying to automate are typed into Microsoft Excel, I simply automate the Alt + Insert + Symbol + Unicode Hex Character code. :)

A typical such sequence to generate this special character looks like this:
SendInput !{vk49}{vk53}          ; Alt + Insert + Symbol
  SendInput !{vk43}                ; jump to character code edit box
  SendInput 05B4                   ; actual unicode hex code of unique char
  SendInput !{vk49}{ENTER}         ; insert & close

I know that this is not a "generic" solution, but the problem itself is not generic, so I can live with that.

Thanks again for your help and explanations!

Gabby