2017-02-10 71 views
0

我以前从未使用过corona sdk,并决定创建一个密钥记录器作为测试以查看我是否喜欢corona。corona sdk在尝试使用io.open打开文件时崩溃

我能够检查输入并指定文件路径,但是一旦我的代码到达io.open,模拟器将冻结并崩溃,并且输入不会添加到文本文件中。

我已经看过几乎所有我能想到的答案,但没有找到答案。

我相信这不是最有效的代码。我是ROBLOX引擎以外的任何类型编程的新手。

function WriteToFile(String) 
     local path = system.pathForFile("[email protected]",  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) 
+0

'io.open(path,“W”)''W“应该是小写的 –

+0

我设法弄清楚了这一点,但感谢评论。 – AZDev

回答

0

遗憾地告诉你这一点,但不幸的是你不能创建科罗娜SDK键盘记录器。您无法创建在后台运行的任何内容。

E.g.你不能做一个浮动小部件,当你按下它时,你会得到截图。

+0

感谢您的回复,但我可以记录使用corona按下的按键。为了不被恶意攻击,我不让它隐藏或运行,因为一个进程并没有打扰到我。 – AZDev

相关问题