Jump to content

Pattern Matching


Recommended Posts

Hi all,

I am working on a an exe (will be posting it soon in the scripts and scraps section), and I need to be able to do some simple string parsing. This would be easy to do in a language like Perl, but I'm having some trouble seeing how to do it in AutoIT.

Specifically, what I want to do is take a HotKeySet() key string, parse it to figure out which keys it specifies, and print out a more human readable string. For example:

CODE
INPUT OUTPUT

------------------------------------------------------

!^a ALT + CTRL + A

#b WIN + B

^+{F1} CTRL + SHIFT + F1

+{Space} SHIFT + SPACE

.

.

.

(This isn't code, just using the box for layout)

Those last two are the real problem -- I'd like to be able to match a pattern inside braces {} .I guess I could just go through with StringReplace() and map every single key binding to a 'nice' output string, but I figure there must be a better way....

Any ideas?

Thanks in advance for your help!

-Matt

Link to comment
Share on other sites

Hope this helps :idiot: There might be some bugs....

MsgBox(4096, "!^a", PrettyPrint("!^a"))
MsgBox(4096, "!^A", PrettyPrint("!^A"))
MsgBox(4096, "#b", PrettyPrint("#b"))
MsgBox(4096, "^+{F1}", PrettyPrint("^+{F1}"))
MsgBox(4096, "+{Space}", PrettyPrint("+{Space}"))
MsgBox(4096, "+{BS}", PrettyPrint("+{BS}"))


Func PrettyPrint($input)
   Local $temp, $output

   If _RemovedFromString($input, "{!}") Then $temp = "!"
   If _RemovedFromString($input, "{#}") Then $temp = "#"
   If _RemovedFromString($input, "{+}") Then $temp = "Plus"
   If _RemovedFromString($input, "{^}") Then $temp = "^"
   If _RemovedFromString($input, "{{}") Then $temp = "{"
   If _RemovedFromString($input, "{}}") Then $temp = "}"
   
   If _RemovedFromString($input, "^") Then $output = $output & "CTRL + "
   If _RemovedFromString($input, "!") Then $output = $output & "ALT + "
   If _RemovedFromString($input, "+") Then $output = $output & "SHIFT + "
   If _RemovedFromString($input, "#") Then $output = $output & "WIN + "
   
  ;Should be left with either a single char or a {...} hotkey
   If _RemovedFromString($input, "{") And _RemovedFromString($input, "}") Then
      $input = StringUpper($input)
      Select
      Case $input = "BS"
         $input = "Backspace"
      Case $input = "DEL"
         $input = "Delete"
      Case $input = "PGUP"
         $input = "PageUp"
      Case $input = "PGDN"
         $input = "PageDown"
      EndSelect
      $output = $output & StringUpper($input)
   ElseIf Asc($input) >= Asc("A") And Asc($input) <= Asc("Z") Then
      $output = $output & "SHIFT + " & $input & " " & $temp
   Else
      $output = $output & StringUpper($input) & $temp
   EndIf
   
   $output = StringStripWS($output, 3) ;removing any leading and trailing whitespace
   If StringRight($output, 1) = "+" Then $output = StringReplace($output, " +", "");remove trailing +

   Return $output
EndFunc


; Helper Function
; If $sub in in $string then remove it and return 1
Func _RemovedFromString(ByRef $string, $sub)
   If StringInStr($string, $sub) Then
      $string = StringReplace($string, $sub, "")
      Return 1
   EndIf
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Hope this helps :D  There might be some bugs....

:idiot: I LOVE YOU!!

Seriously, that works great, and I had just been working on something that was not going the be nearly as good, and I was still pretty satisfied...So this is like Merry Christmas for me :lol:

Anyways, thanks again -- now my exe will be done by the end of the night!

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...