带时间戳的文件记录操纵杆按钮按下

时间:2013-05-24 15:02:15

标签: autohotkey joystick

这是我们在实验室中进行的实验。首先,脚本要求参与者号码并在C:中创建一个文件。在实验期间,具有游戏手柄的参与者按下单个按钮(8),并且每次按下按钮时,文件被写入当前时间。 q按钮返回退出消息并结束脚本。

它不起作用。我认为这个问题围绕着操纵杆。任何帮助非常感谢。

FormatTime, timestamp, , yyyy_MM_dd_HH_mm
JoystickNumber = 1      
#SingleInstance
#persistent

InputBox, ssnum, Subject Number, Please enter the participant number
if ErrorLevel
    ExitApp
else
thefilename=%ssnum%_T_%timestamp%
    FileAppend,
        (
            %ssnum%%timestamp%
        ), C:\%thefilename%.txt
    return

Loop
{
GetKeyState, state, Joy8
    if state = D
        FileAppend,
        (
            %timestamp%, 
        ), C:\%thefilename%.txt
}

q::
MsgBox Exiting.  Your data is saved in the C drive as %thefilename%.txt
ExitApp

1 个答案:

答案 0 :(得分:0)

主要问题是,在你到达循环之前,你正在点击return

我已经清理了你的代码,并将你的循环变成了热键。如果保持密钥,这将阻止对文件的多次写入。如果您需要按住按钮,可以使用您拥有的循环。

FormatTime, timestamp, , yyyy_MM_dd_HH_mm
JoystickNumber = 1      
#SingleInstance
#Persistent

InputBox, ssnum, Subject Number, Please enter the participant number
if ErrorLevel
    ExitApp

thefilename = C:\%ssnum%_T_%timestamp%.txt
FileAppend, %ssnum%`t%timestamp%`n, %thefilename%

~Joy8::
    FormatTime, timestamp, , HH:mm:ss
    FileAppend, %timestamp%`n, %thefilename%
Return

q::
    MsgBox Exiting.  Your data is saved in the C drive as %thefilename%
    Run % thefilename
    ExitApp