Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # function to easily add backspaces
- def insertBS(amount):
- if amount > 1:
- return "Send {Backspace %i}" %(amount)
- elif amount == 1:
- return "Send {Backspace}"
- return ""
- # function to insert newline (ahk code)
- def insertEnter():
- return "Send {Enter}"
- # function to insert space (ahk code)
- def insertSpace(amount):
- if amount > 1:
- return "Send {Space %i}" %(amount)
- elif amount == 1:
- return "Send {Space}"
- return ""
- # function to insert x newlines
- def nl(x):
- return "\n"*x
- # function to detect the amount of indentation
- def detectIndentation(text):
- for i in range(len(text)):
- if text[i] != " ":
- return i
- return 0
- # function to add SendRaw
- def addSend(text):
- return "SendRaw " + text.rstrip('\n').replace("%", "`%")
- # Open and read lua code
- fileName = input("Type in filename: ")
- f = open(fileName, 'r')
- luaCode = f.readlines()
- f.close()
- # initiate ahk code
- ahkCode = "numpad1::" + nl(1)
- curInd = 0
- # loop through lua code lines
- for line in luaCode:
- # detecting and controlling indendtation
- prevInd = curInd
- curInd = detectIndentation(line)
- if curInd < prevInd:
- ahkCode += insertBS(prevInd - curInd) + nl(1)
- # remove unecessary leading spaces (indentation)
- line = line.lstrip(' ')
- if curInd > prevInd:
- ahkCode += insertSpace(curInd - prevInd) + nl(1)
- if len(line.rstrip('\n')) != 0:
- ahkCode += addSend(line) + nl(1)
- ahkCode += insertEnter() + nl(1)
- # add exit command
- ahkCode += nl(1) + "exitapp"
- # save file
- ahkName = fileName.replace(".lua", ".ahk")
- f = open(ahkName, 'w')
- f.write(ahkCode)
- f.close()
- input("Done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement