Jump to content

Mapping key input to a 2d array


Recommended Posts

Hi All!

Using XML file:

<?xml version="1.0" encoding="UTF-8"?>
<keymap>
<binding>
<key>a</key>
<string>This is the first string</string>
</binding>
<binding>
<key>b</key>
<string>This is the second string</string>
</binding>
<binding>
<key>c</key>
<string>This is the first string</string>
</binding>
</keymap>

key 'a' maps to 'This is the first string' and so on. I have managed to parse the xml file into a 2d array as seen below

_XMLFileOpen("list.xml")
   Local $iCount = _XMLGetNodeCount("/keymap/binding")  
   Local $bindings[$iCount+1][2]
      
   For $i = 1 to $iCount
      
      $bindings[$i][0] = _XMLGetFirstValue("/keymap/binding[" & $i & "]/key")
      $bindings[$i][1] = _XMLGetFirstValue("/keymap/binding[" & $i & "]/string")      
      
   Next

What I'm trying to accomplish is not having to write a unque function for each key press. It's impossible to do so when I wont know the contents of the XML file. Are dynamic functions possible?

Any advice on how to map key input as defined in the XML file would be great!

My only lead right now is using HotKeyPress, however it dosn't accept paramaters so I dont know how one would sync it up to a dynamic XML list.

Link to comment
Share on other sites

Ok I have a work around solution ...

I found a Virtual Keyboard here:

It did all the heavy lifting for me by creating a function for each key. Now when 'a' is pressed it spits out the xml!

func A()
   ConsoleWrite( $bindings[1][1] )
  
GUICtrlSetBkColor($a, 0xF2F22C)
sleep(200)
GUICtrlSetBkColor($a, 0xFBFFFA)
endfunc

Hope this helps someone

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