#!/usr/bin/env python
import re, sys, os
if len(sys.argv) != 2:
    print >>sys.stderr, "Usage: win.py path/to/WinUser.h"
    sys.exit(1)
OUT = 'win2.txt'
TMP = OUT + '.tmp'
f = open(TMP, 'w')
try:
    print >>f, '; Automatically generated by "win.py"'
    VK = re.compile('#define\s*VK_(\w+)\s+(\w+)')
    for line in open(sys.argv[1], 'r'):
        m = VK.match(line)
        if m:
            n, i = m.groups()
            i = int(i, 0)
            print >>f, '%d\t%s' % (i, n)
    f.close()
    os.rename(TMP, OUT)
except:
    try:
        os.unlink(TMP)
    except OSError:
        pass
    raise

Add keycode table generator for Windows
Add keycode table generator for Windows
