Jump to content
Sign in to follow this  
gcue

convert scan codes to hexadecimal

Recommended Posts

gcue

hello world!

i am trying to find a way to convert a string of text to hexadecimal.  but the results I am getting from help and on the forum dont match up with this example 


“kbd” denotes a string in hexadecimal format containing keyboard
scan code input. This feature should be supported by all BIOS
implementations. An example of a password structured in this format
would be “<kbd/>321539191E1F1F11181320”, which is “my
password” in US keyboard scan codes.

 

is scan code different than just regular text?  what conversion can i use to match it?

thank you in advance!!!

Share this post


Link to post
Share on other sites
GPinzone

Scan codes: http://msdn.microsoft.com/en-us/library/aa299374%28v=vs.60%29.aspx

It's different than ASCII. If a letter to scan code function doesn't exist in AutoIt, you can make one easy enough. Just make an array that converts scan code numbers to ASCII codes and then return the key using the existing ASCII character commands.


Gerard J. Pinzonegpinzone AT yahoo.com

Share this post


Link to post
Share on other sites
Yashied

#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

$Text = 'MY PASSWORD'

; Characters to scan codes
$Data = StringRegExp(StringUpper($Text), '.{1}', 3)
$Text = ''
For $i = 0 To UBound($Data) - 1
    $Text &= Hex(_WinAPI_MapVirtualKey(Asc($Data[$i]), $MAPVK_VK_TO_VSC), 2)
Next

ConsoleWrite($Text & @CR)

; Scan codes to characters
$Data = StringRegExp($Text, '.{2}', 3)
$Text = ''
For $i = 0 To UBound($Data) - 1
    $Text &= Chr(_WinAPI_MapVirtualKey(Dec($Data[$i]), $MAPVK_VSC_TO_VK))
Next

ConsoleWrite($Text & @CR)

Share this post


Link to post
Share on other sites
gcue

thanks yashield.  unfortunately - i dont have those includes (APIConstants nor WinAPIEx) - i have v3.3.8.1 and v3.3.9.19 beta installed.  how can i get them?

Share this post


Link to post
Share on other sites
Yashied
gcue

hmm as i incorporated it into my script, im getting conflicts with other udfs

any idea which one im conflicting with?  dunno what the best solution would be either - remove the word Const from both?  or should i make this converter its own script and call it from the main script to get the conversion text?

thanks again for your help!


C:Program FilesAutoIt3IncludeAPIConstants.au3(3636,110) : ERROR: $KEY_READ previously declared as a 'Const'
Global Const $KEY_READ = BitOR($STANDARD_RIGHTS_READ, $KEY_ENUMERATE_SUB_KEYS, $KEY_NOTIFY, $KEY_QUERY_VALUE)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Program FilesAutoIt3IncludeAPIConstants.au3(3637,93) : ERROR: $KEY_WRITE previously declared as a 'Const'
Global Const $KEY_WRITE = BitOR($STANDARD_RIGHTS_WRITE, $KEY_CREATE_SUB_KEY, $KEY_SET_VALUE)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Program FilesAutoIt3IncludeWinAPIEx.au3(1044,399) : ERROR: $tagTEXTMETRIC previously declared as a 'Const'
Global Const $tagTEXTMETRIC = 'long tmHeight;long tmAscent;long tmDescent;long tmInternalLeading;long tmExternalLeading;long tmAveCharWidth;long tmMaxCharWidth;long tmWeight;long tmOverhang;long tmDigitizedAspectX;long tmDigitizedAspectY;wchar tmFirstChar;wchar tmLastChar;wchar tmDefaultChar;wchar tmBreakChar;byte tmItalic;byte tmUnderlined;byte tmStruckOut;byte tmPitchAndFamily;byte tmCharSet;'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(301,31) : ERROR: $FO_MOVE previously declared as a 'Const'
Global Const $FO_MOVE = 0x0001
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(302,31) : ERROR: $FO_COPY previously declared as a 'Const'
Global Const $FO_COPY = 0x0002
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(303,33) : ERROR: $FO_DELETE previously declared as a 'Const'
Global Const $FO_DELETE = 0x0003
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(304,33) : ERROR: $FO_RENAME previously declared as a 'Const'
Global Const $FO_RENAME = 0x0004
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(306,42) : ERROR: $FOF_MULTIDESTFILES previously declared as a 'Const'
Global Const $FOF_MULTIDESTFILES = 0x0001
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(307,40) : ERROR: $FOF_CONFIRMMOUSE previously declared as a 'Const'
Global Const $FOF_CONFIRMMOUSE = 0x0002
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(308,34) : ERROR: $FOF_SILENT previously declared as a 'Const'
Global Const $FOF_SILENT = 0x0004
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(309,45) : ERROR: $FOF_RENAMEONCOLLISION previously declared as a 'Const'
Global Const $FOF_RENAMEONCOLLISION = 0x0008
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(310,42) : ERROR: $FOF_NOCONFIRMATION previously declared as a 'Const'
Global Const $FOF_NOCONFIRMATION = 0x0010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(311,45) : ERROR: $FOF_WANTMAPPINGHANDLE previously declared as a 'Const'
Global Const $FOF_WANTMAPPINGHANDLE = 0x0020
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(312,37) : ERROR: $FOF_ALLOWUNDO previously declared as a 'Const'
Global Const $FOF_ALLOWUNDO = 0x0040
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(313,37) : ERROR: $FOF_FILESONLY previously declared as a 'Const'
Global Const $FOF_FILESONLY = 0x0080
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(314,42) : ERROR: $FOF_SIMPLEPROGRESS previously declared as a 'Const'
Global Const $FOF_SIMPLEPROGRESS = 0x0100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(315,42) : ERROR: $FOF_NOCONFIRMMKDIR previously declared as a 'Const'
Global Const $FOF_NOCONFIRMMKDIR = 0x0200
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(316,37) : ERROR: $FOF_NOERRORUI previously declared as a 'Const'
Global Const $FOF_NOERRORUI = 0x0400
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(317,49) : ERROR: $FOF_NOCOPYSECURITYATTRIBS previously declared as a 'Const'
Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x0800
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(318,39) : ERROR: $FOF_NORECURSION previously declared as a 'Const'
Global Const $FOF_NORECURSION = 0x1000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(319,49) : ERROR: $FOF_NO_CONNECTED_ELEMENTS previously declared as a 'Const'
Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(320,43) : ERROR: $FOF_WANTNUKEWARNING previously declared as a 'Const'
Global Const $FOF_WANTNUKEWARNING = 0x4000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:Scriptsgenie v0.4.3.8.au3(321,44) : ERROR: $FOF_NORECURSEREPARSE previously declared as a 'Const'
Global Const $FOF_NORECURSEREPARSE = 0x8000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Share this post


Link to post
Share on other sites
BrewManNH

thanks yashield.  unfortunately - i dont have those includes (APIConstants nor WinAPIEx) - i have v3.3.8.1 and v3.3.9.19 beta installed.  how can i get them?

The beta version 3.3.9.19 does have those files as includes, they're standard in that  version now, that's why you're getting so many errors.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
gcue

actually i also tried it on a 3.3.6.1 version (on another PC)

copied over the udfs in which they did not exist.  getting the errors there too

Share this post


Link to post
Share on other sites
BrewManNH

You must have 2 copies of APIConstants.au3 in different folders, it's loading both.

Also, this script genie v0.4.3.8.au3 is causing most of the errors, not sure why you are declaring these variables in that script if they're already declared elsewhere.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
gcue

i dont see the second copy of apiconstants

 

Also, this script genie v0.4.3.8.au3 is causing most of the errors, not sure why you are declaring these variables in that script if they're already declared elsewhere.

 

i am not declaring anything.  so it has to be another udf that is trying to figure out which one but dont think that will matter because there are duped declarations it seems - probably better to go interscript communication with this i think

Share this post


Link to post
Share on other sites
Yashied

Copy the following lines into your script and enjoy.

 

Global Const $MAPVK_VK_TO_VSC = 0
Global Const $MAPVK_VSC_TO_VK = 1

Func _WinAPI_MapVirtualKey($iCode, $iType, $hLocale = 0)

    Local $Ret = DllCall('user32.dll', 'uint', 'MapVirtualKeyExW', 'uint', $iCode, 'uint', $iType, 'uint_ptr', $hLocale)

    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_MapVirtualKey

Share this post


Link to post
Share on other sites
gcue

looks cool - except not sure what the itype variable looks like

also, i wont be needing those includes then right?

thanks soo much for your help!!!  greatly appreciated.

$text = '1234567'

$scan_codes = _WinAPI_MapVirtualKey($text)
ConsoleWrite($scan_codes & @CR)
 
Global Const $MAPVK_VK_TO_VSC = 0
Global Const $MAPVK_VSC_TO_VK = 1
 
Func _WinAPI_MapVirtualKey($iCode, $iType, $hLocale = 0)
 
    Local $Ret = DllCall('user32.dll', 'uint', 'MapVirtualKeyExW', 'uint', $iCode, 'uint', $iType, 'uint_ptr', $hLocale)
 
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_MapVirtualKey
Edited by gcue

Share this post


Link to post
Share on other sites
gcue

i tried both of these to no avail

(thinking maybe the itype is either 0 or 1 (Const variables)  

sorry i have no idea what to plug in

$text = '1234567'
 
$scan_codes = _WinAPI_MapVirtualKey($text, 0)
ConsoleWrite($scan_codes & @CR)
 

$scan_codes = _WinAPI_MapVirtualKey(0, $text)
ConsoleWrite($scan_codes & @CR)
Edited by gcue

Share this post


Link to post
Share on other sites
gcue

nevermind!!! i got it!  hahahha

so sorry man.

no includes needed.. and here's the full script (for anyone who reads/needs this later..)

thanks again yashield!!!

Global Const $MAPVK_VK_TO_VSC = 0
Global Const $MAPVK_VSC_TO_VK = 1
 
$text = '1234567'
 
$scan_codes = Convert_Characters_To_Scan_Codes($text)
ConsoleWrite($scan_codes & @CR)
ClipPut($scan_codes)
 
Func Convert_Characters_To_Scan_Codes($text)
 
; Characters to scan codes
$data = StringRegExp(StringUpper($text), '.{1}', 3)
$text = ''
For $i = 0 To UBound($data) - 1
$text &= Hex(_WinAPI_MapVirtualKey(Asc($data[$i]), $MAPVK_VK_TO_VSC), 2)
Next
 
Return $text
 
EndFunc   ;==>Convert_Characters_To_Scan_Codes
 
$characters = Convert_Scan_Codes_To_Characters($scan_codes)
ConsoleWrite($characters & @CR)
 
Func Convert_Scan_Codes_To_Characters($text)
 
; Scan codes to characters
$data = StringRegExp($text, '.{2}', 3)
$text = ''
For $i = 0 To UBound($data) - 1
$text &= Chr(_WinAPI_MapVirtualKey(Dec($data[$i]), $MAPVK_VSC_TO_VK))
Next
 
Return $text
 
EndFunc   ;==>Convert_Scan_Codes_To_Characters
 
 
Func _WinAPI_MapVirtualKey($iCode, $iType, $hLocale = 0)
 
    Local $Ret = DllCall('user32.dll', 'uint', 'MapVirtualKeyExW', 'uint', $iCode, 'uint', $iType, 'uint_ptr', $hLocale)
 
    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_MapVirtualKey

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×