AutoHotkey Community

It is currently May 26th, 2012, 12:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: September 6th, 2007, 11:09 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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:

Code:
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%
}


:)


Last edited by SKAN on September 7th, 2007, 9:37 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2007, 11:35 pm 
Offline

Joined: July 20th, 2007, 10:23 am
Posts: 257
Location: Paris, France
Thanks, this will be definitively very useful. :)
In fact, maybe the Key List section of the help should have a link on this topic.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2007, 9:43 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Andreone wrote:
maybe the Key List section of the help should have a link on this topic.


I am not sure whether this the same as the method given in Help doc. :roll:
I have altered the code to monitor more messages, like some keys like <PrtScr> were detected on key-release instead of key-press.

Code:
WM_KEYDOWN     = 0x100
WM_KEYUP       = 0x101
WM_CHAR        = 0x102
WM_DEADCHAR    = 0x103
WM_SYSKEYDOWN  = 0x104
WM_SYSKEYUP    = 0x105
WM_SYSCHAR     = 0x106
WM_SYSDEADCHAR = 0x107
WM_KEYLAST     = 0x108


I have only a basic multimedia keyboard and could not test this much!

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Keyboard Hook - 90L
PostPosted: July 15th, 2008, 3:41 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
    Image



Code:
; Keyboard Hook - Crude Script to retrieve info on "Mystery keys" - By Skan
; Created : 15-Jul-2008  // Last Modifed : 15-Jul-2008 
;
; Note: Yet to be bug-fixed and optimised!!!

#SingleInstance, Force
#Persistent
#InstallKeybdHook
#KeyHistory 20
SetWorkingDir, %A_ScriptDir%

VKeys=
( join
VK_LBUTTON,VK_RBUTTON,VK_CANCEL,VK_MBUTTON,VK_XBUTTON1,VK_XBUTTON2,,VK_BACK,VK_TAB,Reserve
d,Reserved,VK_CLEAR,VK_RETURN,,,VK_SHIFT,VK_CONTROL,VK_MENU,VK_PAUSE,VK_CAPITAL,VK_HANGUL,
,VK_JUNJA,VK_FINAL,VK_HANJA,,VK_ESCAPE,VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,VK
_SPACE,VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,VK_SELECT,VK_PRINT,V
K_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,VK_HELP,VK_0,VK_1,VK_2,VK_3,VK_4,VK_5,VK_6,VK_7,
VK_8,VK_9,,,,,,,,VK_A,VK_B,VK_C,VK_D,VK_E,VK_F,VK_G,VK_H,VK_I,VK_J,VK_K,VK_L,VK_M,VK_N,VK_
O,VK_P,VK_Q,VK_R,VK_S,VK_T,VK_U,VK_V,VK_W,VK_X,VK_Y,VK_Z,VK_LWIN,VK_RWIN,VK_APPS,Reserved,
VK_SLEEP,VK_NUMPAD0,VK_NUMPAD1,VK_NUMPAD2,VK_NUMPAD3,VK_NUMPAD4,VK_NUMPAD5,VK_NUMPAD6,VK_N
UMPAD7,VK_NUMPAD8,VK_NUMPAD9,VK_MULTIPLY,VK_ADD,VK_SEPARATOR,VK_SUBTRACT,VK_DECIMAL,VK_DIV
IDE,VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,VK_F11,VK_F12,VK_F13,VK_F
14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,VK_F21,VK_F22,VK_F23,VK_F24,,,,,,,,,VK_NUMLOC
K,VK_SCROLL,OEM,OEM,OEM,OEM,OEM,,,,,,,,,,VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LM
ENU,VK_RMENU,VK_BROWSER_BACK,VK_BROWSER_FORWARD,VK_BROWSER_REFRESH,VK_BROWSER_STOP,VK_BROW
SER_SEARCH,VK_BROWSER_FAVORITES,VK_BROWSER_HOME,VK_VOLUME_MUTE,VK_VOLUME_DOWN,VK_VOLUME_UP
,VK_MEDIA_NEXT_TRACK,VK_MEDIA_PREV_TRACK,VK_MEDIA_STOP,VK_MEDIA_PLAY_PAUSE,VK_LAUNCH_MAIL,
VK_LAUNCH_MEDIA_SELECT,VK_LAUNCH_APP1,VK_LAUNCH_APP2,Reserved,Reserved,VK_OEM_1,VK_OEM_PLU
S,VK_OEM_COMMA,VK_OEM_MINUS,VK_OEM_PERIOD,VK_OEM_2,VK_OEM_3,Reserved,Reserved,Reserved,Res
erved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,Res
erved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,Reserved,,,,
VK_OEM_4,VK_OEM_5,VK_OEM_6,VK_OEM_7,VK_OEM_8,Reserved,OEM,VK_OEM_102,OEM,OEM,VK_PROCESSKEY
,OEM,VK_PACKET,,OEM,OEM,OEM,OEM,OEM,OEM,OEM,OEM,OEM,OEM,OEM,OEM,OEM,VK_ATTN,VK_CRSEL,VK_EX
SEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,VK_PA1,VK_OEM_CLEAR,0xFF

)
StringSplit, VK, VKeys, `,

DetectHiddenWindows, On
Gui0 := WinExist( A_ScriptFullPath " ahk_class AutoHotkey" )
Gui, Margin,0,0
Gui 1:+LastFound -Sysmenu +AlwaysOnTop +ToolWindow
Gui1 := WinExist()
WinSet, style, -0xC00000, ahk_id %Gui0%
WinMove, ahk_id %Gui0%,,0,-30,640,25
ControlSend,,^{k}, ahk_id %Gui0%
DllCall("SetParent", uint, Gui0, uint,Gui1 )
Gui, Font, S10, Courier New
Gui, Add, ListView, Grid w605 r20 -E0x200, VK-Name|VKey|Scan|C|^|Elap|Hotkey Name
LV_ModifyCol(1, "190"), LV_ModifyCol( 2,"60 Center"), LV_ModifyCol(3,"60 Center")
LV_ModifyCol(4, "40 Center"), LV_ModifyCol(5,"40 Center"), LV_ModifyCol( 6,"60 Integer")
LV_ModifyCol(7, "150")
Gui, Show, , % " |<< Keyboard Hook >>|"
OnExit, QuitScript
SetTimer, UpdateListView, 10
Return

UpdateListView:
  If ! ( WinActive( "ahk_id" Gui1 ) OR WinActive( "ahk_id" Gui0 ) )
       Return 
  ControlSend,,{F5}, ahk_id %Gui0%
  ControlGetText, text, Edit1, ahk_id %Gui0%
  VarSetCapacity( hyphens, 109, Asc("-") )
  nText := SubStr( Text,(sPos:=InStr( Text,hyphens )+111), StrLen(Text)-Spos )
  StringReplace,nText,nText,Press [F5] to refresh,,
  StringReplace,nText,nText,%A_Tab%,|,all
  StringTrimRight,nText,nText,2
  If ( nText = pText )
     Return
  Gui, 1:Default
  LV_Delete()
  Loop, Parse, nText, `n, `r
   {
     Line := A_LoopField
     Loop,Parse,Line,|
      F%A_Index% := A_LoopField
     VKey := "VK" SubStr(F1,1,2), VK := "0x" SubStr(F1,1,2),
     VK += 0
     VK := "VK" VK, SC := "SC" SubStr(F1,-2), VKN := %VK%
     LV_Add( "", VKN, VKey, SC,F2, F3, F4, F5 ) 
   }
  pText := nText
Return

QuitScript:
 ExitApp
Return


.. Run the code, make sure script's GUI has keyboard focus, press a key ..

:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2008, 7:59 am 
Offline

Joined: July 17th, 2008, 7:16 pm
Posts: 15
Thanks, useful; but on my system some column are too narrow ...

http://img185.imageshack.us/img185/2932/purrint1645pa5.jpg


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2008, 1:21 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Try altering
Code:
Gui, Font, S10, Courier New

to S9 or S8

:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2008, 11:23 pm 
Offline

Joined: July 17th, 2008, 7:16 pm
Posts: 15
With S8 is ok, thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2008, 7:04 pm 
Offline

Joined: September 20th, 2006, 2:05 pm
Posts: 73
amazing. very useful. thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2008, 8:17 am 
Offline

Joined: December 19th, 2006, 2:14 pm
Posts: 72
Location: France
This one was needed. thanks Skan. It slipped right into my toolbox :)

PS : a funny bug I got : when pressing CAPS LOCK, the LED keeps flashing until I release CAPS.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 3:42 am 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
This is a great little app, thanks. :) I'm not sure if this is just my keyboard, but the scancodes reported for the Multimedia buttons are not the same as key history or your keyboard hook script, although they are quite similar. I tried remapping them with the scancodes returned and they don't work:

Code:
ahk         app         key   
12e         02e         vol up
130         030         vol down      
119         019         next
110         010         prev
120         020         mute
124         024         stop
122         022         play/pause
132         032         disconnect
166         066         favourites
165         065         find
16c         06c         mail
15f         05f         sleep
?           05e         shutdown

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 5:30 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Serenity wrote:
but the scancodes reported for the Multimedia buttons are not the same as key history or your keyboard hook script


Very strange. All the buttons are correctly reported for my USB KB as well as my trashed PS2 Keyboard. :roll:

Are you using any special driver / software that came along with your KB ?

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2008, 10:37 am 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
SKAN wrote:
Are you using any special driver / software that came along with your KB ?


No, just the standard 101/102-key MS driver.

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 6:05 pm 
Offline

Joined: October 13th, 2009, 6:01 pm
Posts: 6
awesome. cheers for this I found it very useful re-mapping the 4 hot keys on my BenQ notebook.
(Net, Mail, P1, P2) their numbers are SC173, SC174, SC16c, SC132.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 25th, 2009, 4:29 pm 
Offline

Joined: October 14th, 2009, 12:30 am
Posts: 20
SKAN wrote:
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:

Code:
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%
}


:)


A big, huge, gigantic thank you for this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 25th, 2009, 5:26 pm 
Get the "scancode" with "skancode" :lol:


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: bbwht, Exabot [Bot], Morpheus and 56 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