Jump to content

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

Crazy Scripting : Scriptlet to find Scancode of a Key


  • Please log in to reply
36 replies to this topic
magusgulf
  • Members
  • 13 posts
  • Last active: May 03 2011 10:05 AM
  • Joined: 16 Feb 2011
This is simply great to conveniently remap the keyboard AND make sure it works exactly the same for layouts of any language.

Thanks a million.


While experimenting with a keylogger that captures system-wide key strokes using a hook, I transferred a small snippet of the code which works in AHK natively.

Nothing special. Run it and when GUI is in focus press a key and the clipboard will contain the scancode of the key which can be used as hotkey or with Send commands:

SetFormat, Integer, Hex
Gui +ToolWindow -SysMenu +AlwaysOnTop
Gui, Font, s14 Bold, Arial
Gui, Add, Text, w100 h33 vSC 0x201 +Border, {SC000}
Gui, Show,, % "// ScanCode //////////"
Loop 9
  OnMessage( 255+A_Index, "ScanCode" ) ; 0x100 to 0x108
Return

ScanCode( wParam, lParam ) {
 Clipboard := "SC" SubStr((((lParam>>16) & 0xFF)+0xF000),-2) 
 GuiControl,, SC, %Clipboard%
}

:)



AEN007
  • Members
  • 136 posts
  • Last active: Feb 07 2012 05:24 PM
  • Joined: 04 Apr 2009
AWESOME ...
Thanks to this script I was able to ID the scancode for the ä/Ä key on my DE keyboard and
remap that key in the registry to the RightAlt key - of which there is none on the DE keyboard ...
I searched & searched (to no avail) on the web for the scancode for that key ...

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Guess you didn't know about the built-in KeyHistory command?

AEN007
  • Members
  • 136 posts
  • Last active: Feb 07 2012 05:24 PM
  • Joined: 04 Apr 2009
9March2011

Good guess ... and thanks ... always welcome learning something new about AHK
(about which I probably don't know half of what there is to know ...
but I probably know more than Bill Gates about AHK ...)
... anyway, I found that I could remap ä/Ä with neither SharpKeys nor KeyTweak.
I then decided the Insert key would be even better than ä/Ä to remap as the AltRight key.
I then found that Insert is in general a(nother) un-remappable key.

I read about SC:: remapping but searched the web (this time not in vain) some more.
I found the following»ReMapKey which seems to be the BEST (individual key) remapping utility I've found.
I remapped Insert to AltRight and ü/Ü to Insert ... (with simple mouse clicks ...)
to go along with some other bizarre remappings I had already done
(like Pause to Delete - with all of the complications that involved ...DevBlog)
So now I could remap ä/Ä & ö/Ö ... if I ever think of a useful way to remap them ...
Any helpful replies/insights appreciated.
Thank you.
Regards,
AEN
Æ

AEN007
  • Members
  • 136 posts
  • Last active: Feb 07 2012 05:24 PM
  • Joined: 04 Apr 2009
10March2011

Greetings.

One obscure question/issue I would like to resolve.
The keyboard in question is a mini/backlit PS2 keyboard auf Deutsch.
The lower right corner standard layout is:
AltGr ¦ RWin ¦ AppsKey ¦ Insert ¦ Delete ¦ Left ¦ Down ¦ Right
I don't like the Delete key there ... too dangerous.

I remapped Delete to RCtrl and Pause to Delete ...
As per previous posts, I just remapped Insert to RAlt.
Alt-Ctrl-Left & Alt-Ctrl-Right are common App/Util hotkeys.

I now have LCtrl, LAlt, RCtrl & RAlt keys and can now much more easily do A-C-L & A-C-R with my new RCtrl & RAlt keys; however, RC-RA-Right is not working!

RC-RA-Left works. LC-RA-Right works ... all combinations of A-C-L work and, all combinations of A-C-R work
EXCEPT RC-RA-Right (the one I want!)

I have no idea why this one little key combo isn't working.

Any helpful replies/insights appreciated.
Thank you.
Regards,
AEN
Æ

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
This is ontopic, and I don't understand why I PMd SKAN about it (sorry)... anyway:

Is there any good way to find out what the actual (or virtual) key is, if you have the scancode?

This tool gives key -> scancode. I wanna see scancode -> key. How?

(Planning to use it for an improved hotkeyselector in GUIs)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I PMd SKAN about it


Sorry for the late reply. ^_^;

Is there any good way to find out what the actual (or virtual) key is, if you have the scancode?


;MapVirtualKeyEx :: www.msdn.microsoft.com/en-us/library/ms646306(VS.85).aspx

scancode := 0x01E ; Char 'A'
MAPVK_VSC_TO_VK_EX := 3

MsgBox, % DllCall( "MapVirtualKeyEx"
                  , UInt,scancode
                  , UInt,MAPVK_VSC_TO_VK_EX
                  , Int,0 )

(Planning to use it for an improved hotkeyselector in GUIs)


Have you seen shimanov's custom hotkey control?

AEN007
  • Members
  • 136 posts
  • Last active: Feb 07 2012 05:24 PM
  • Joined: 04 Apr 2009

So now I could remap ä/Ä & ö/Ö ... if I ever think of a useful way to remap them ...

It occurred to me that the ö & ä keys would be perfect if they were like the [{ & ]} keys.
Of course remapping them was not at all easy. Seems it can not be done in the registry. So I came up with this»
ö::
ErrorLevel := 0
KeyWait, RShift, DT.5
If (ErrorLevel = 0)
 Send {{}
else Send [
Send {Alt Up}
Send {Ctrl Up}
Send {LWin Up}
Send {Shift Up}
Return

ä::
ErrorLevel := 0
KeyWait, RShift, DT.5
If (ErrorLevel = 0)
 Send {}}
else Send ]
Send {Alt Up}
Send {Ctrl Up}
Send {LWin Up}
Send {Shift Up}
Return

ü::
ErrorLevel := 0
KeyWait, RShift, DT.5
If (ErrorLevel = 0)
 Send \
else Send /
Send {Alt Up}
Send {Ctrl Up}
Send {LWin Up}
Send {Shift Up}
Return
and added it to one of my persistent hotkey scripts.
I moved the Insert key remapping from ü/Ü to the `´ and remapped ü/Ü to / & \ ...

The / & \ keys are in "weird" places on the DE keyboard.
The brackets/braces keys can only be typed by using the AltGr key on the DE keyboard ...

Would like to know of any better ways to do this ...

Any helpful replies/insights appreciated.
Thank you.
Regards,
AEN
Æ

AEN007
  • Members
  • 136 posts
  • Last active: Feb 07 2012 05:24 PM
  • Joined: 04 Apr 2009
I would like to improve these hotkey scripts.
The scripts wait .5 sec for the shift key. If I hit some other key(s) instead of shift without waiting .5 sec,
those keys are input ahead of the `/ or `[ or `] ...
I could use INPUT, but would have to specify every/all other possible keys as endkeys ...
is there other/better options?

AEN007
  • Members
  • 136 posts
  • Last active: Feb 07 2012 05:24 PM
  • Joined: 04 Apr 2009
26April2011

... so I did two more registry key remappings on the laptop in question.
I remapped CAPS to WinKey & LWin to AppsKey.
I had already remapped CAPS to WinKey on my IBM laptop with no WinKey.
CAPS is a BIG waste of space on the keyboard.
Makes a great WinKey.
I tweaked one of my persistent AHK scripts to manage toggling CAPS.

Now I have an AppsKey on the left & right sides of this other laptop of mine ... in fact I have left & right WinKeys, AppsKeys, Alt, Ctrl & Shift keys ...

Guesty
  • Guests
  • Last active:
  • Joined: --
First of all, nice script! Imminently useful. However, and it may be that I'm overlooking something obvious, when I utilize it to ascertain the scan codes of the media control keys on my ASUS A53E-EH91 (which are Fn + the arrow keys), the scan code for each is the same. Namely, SC-023.

Perhaps the scan code is actually an ACPI event or something? I don't know, and I'm having a troublesome time trying to re-map them to anything but Windows Media Center (which has been virulently disabled).

EdScriptNewbie
  • Members
  • 117 posts
  • Last active: Aug 19 2013 07:32 PM
  • Joined: 20 Jan 2007
1) what is the "C" column? I notice in your example that every keystroke in your example screen has "a" in that column; mine either have "i" or blank. THANKS

2) Here's why I'm asking: do you have any suggestions on the following? I'm trying to diagnose why my system (xp on vmware fusion) instantly sends dozens of up-downs of either Shift or Control, even though I have Control Panel Keyboard set to long delay slow repeat. The first down stroke the C is blank, followed by a bunch of up-downs (not always in pairs) that have an i in the C column, and ending with an up with a blank C column.

CapsLock is even worse, sending an apparently infinite number of VK_CAPITAL keystrokes. Once Caps Lock is on, your program just shows a VK_CAPITAL down-up (C=i) for any key press, and the pressed key isn't shown at all. These problems are true when your script is the only AHk script running, so it doesn't seem to be coming from another script. THANKS
...Ed

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

1) what is the "C" column? I notice in your example that every keystroke in your example screen has "a" in that column; mine either have "i" or blank.


I do not remember why I chose "C" as column header.
"C" column shows the Input Type which could be one of the following:

h=Hook Hotkey,
s=Suppressed (blocked),
i=Ignored because it was generated by an AHK script,
a=Artificial,
#=Disabled via #IfWinActive/Exist.

The 'example screen' was most probably taken in Windows 98, in which hotkeys are managed very differently from Windows NT ( a hook DLL will be injected into target process ) .

I am not qualified to answer the rest of question as I do not have any idea about "VMware Fusion"
kWo4Lk1.png

EdScriptNewbie
  • Members
  • 117 posts
  • Last active: Aug 19 2013 07:32 PM
  • Joined: 20 Jan 2007
Thanks. I took this with only one ahk script running, your key logger. A quick tap on the shift key gives me a bunch of those ignored keystrokes. Any thoughts as to what might be going wrong? (I'm by no means sure that AHk is causing this, but nothing else is running, I even turned McAfee off).
THANKS
...Ed
PS, in everything else I've done, XP on the the VMWare platform has behaved like my Dell.
Posted Image
...Ed

EdScriptNewbie
  • Members
  • 117 posts
  • Last active: Aug 19 2013 07:32 PM
  • Joined: 20 Jan 2007
I have no reason to think the problem is from AutoHotkey, but I'd like to eliminate that. There's no way to tell unless I can log keys without AutoHotkey running. But a key logger seems like a pretty dangerous thing to download from the internet. Do you know of any safe key logger I could try? THANKS
...Ed