2017-02-10 105 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

相關問題