Jump to content

regex to prepend '0x' to string chunks


 Share

Recommended Posts

with dllstruct syntax you can have a similar syntax than an array index:

$arr = DllStructCreate('byte b[256]')
DllCall('user32.dll', 'bool', 'GetKeyboardState', 'struct*', $arr)
$arr.b( 1 + $VK_CONTROL) ; <<<< VK_CONTROL byte

otherwise you will need to get a string with the One-Liner array (and then convert back to number on demand)

$arr = StringRegExp(StringRegExpReplace(DllStructGetData(_WinAPI_GetKeyboardState(),1),'[[:xdigit:]]{2}','0x$0'),'.{4}',3,3)
_ArrayDisplay($arr)

;  yeyeah one-liner \o/

 

Link to comment
Share on other sites

I'm highly skeptical that a key can both toggled on and down.   for some reason it looks that way it's most likely a 0 in 0x8 is being cut off, but it's impossible to tell bc the data isn't separated as intended.   Regex is looping through the string you just don't see it, it's just happening elsewhere.   

Link to comment
Share on other sites

2 hours ago, markyrocks said:

Regex is looping through the string you just don't see it, it's just happening elsewhere.   

That's basicaly what i wanted to say (but sometimes i refrain myself this kind of comment ^^), but it is done with some optimized compiled code, so it's far faster than a native AutoIt loop. Anyway if you want to split your data (as numbers) into some AutoIt array, you will need to loop through it at a moment or another.

2 hours ago, markyrocks said:

I'm highly skeptical that a key can both toggled on and down.

Well it's just the state, the toggling is handled when the key_down 'event' is fired. You pressed: it toggle, but as long as you hold the key it's still down ...

2 hours ago, markyrocks said:

 for some reason it looks that way it's most likely a 0 in 0x8 is being cut off, but it's impossible to tell bc the data isn't separated as intended.

It's just about the bit (low or high order, 'righter' or 'lefter'), there's no hex cutoff or stuff like that (also 0x8 will be nor toggled nor down, it is a bitmask) (you can see in my code i handle the stuff by cheking the bits themself)

Edited by 636C65616E
Link to comment
Share on other sites

Well i'll be, I did a test and it does output a 0x81.   That is true about optimized compiled code but I was thinking that the nature of a strings being somewhat slow as are string comparisons that it might be possible that an autoit loop simply evaluating a a bool statement could be faster but what was i thinking lol.     Ok I think I got it figured out its kinda simple and but its fast and it does make sense even though the math is weird due to mixing what amounts to a 0 based array and a 1 based index on the binary string but it is fast.  Its not going to display via array display but it seems to be the ticket.

#include <WinAPISys.au3>

$struct = DllStructCreate("struct;byte[256];endstruct",DllStructGetPtr(_WinAPI_GetKeyboardState()))

$timer = TimerInit()

$binary = Binary(DllStructGetData($struct,1)) ;once you are here you have what amounts to a binary array accessed via $state = BinaryMid($binary,$key_code+1,1(byte))

ConsoleWrite("timer = " & TimerDiff($timer) & "ms" & @CRLF)

for $x = 1 to BinaryLen($binary) ;just for display purposes
        ConsoleWrite("key = 0x" & Hex($x-1,2) & " State " & Int(BinaryMid($binary,$x,1)) & @CRLF)
Next

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...