2014-10-09 19 views
2

似乎是一個愚蠢的問題,但我無法在Docs中找到如何在PsychoPy Builder實驗中從用戶獲取文本輸入。獲取來自參與者的自由文本(字符串)輸入

例如,如果我有一個文本組件來顯示消息「你叫什麼名字?」

我想獲得文本答案(鍵回顯到屏幕)並將其保存到結果文件中。

我必須放入代碼並使用對話框嗎?

謝謝

回答

1

有兩種選擇:(1)使用對話框,如你所說。您可能需要讓主窗口不是全屏,或者暫時將其最小化,以便可以在前面看到對話框。 (2)手動按下按鈕並將其鏡像到文本組件中的屏幕上。是的,如果這是內置的,它會很好,但它目前不是。通過這個廣泛的線程瞭解如何將這種方法併入Builder中的一些建議:https://groups.google.com/forum/#!topic/psychopy-users/lE_bTMHUAoU

另請參閱此線程:https://groups.google.com/forum/#!topic/psychopy-users/DGXkU-31MPg帶有指向某些代碼形式的指針Alex Holcombe。

3

謝謝邁克爾。看起來它會做的伎倆,但我希望更簡單的交給一個非編程研究人員,所以我有一個戲劇,並提出以下滿足我的要求。

我堅持的代碼到GitHub上這裏https://github.com/jacanterbury/PsychoPy-snippets

但基本上它具有下列功能:

TextStim文本字段包含此:

$(word + '\n' + inputText) 

在同一迴路A碼對象有此:

開始實驗:

inputText = "" 

開始例程:

theseKeys="" 
shift_flag = False 
text_3.alignHoriz ='left' 

每個幀:

n= len(theseKeys) 
i = 0 
while i < n: 

    if theseKeys[i] == 'return': 
     # pressing RETURN means time to stop 
     continueRoutine = False 
     break 

    elif theseKeys[i] == 'backspace': 
     inputText = inputText[:-1] # lose the final character 
     i = i + 1 

    elif theseKeys[i] == 'space': 
     inputText += ' ' 
     i = i + 1 

    elif theseKeys[i] in ['lshift', 'rshift']: 
     shift_flag = True 
     i = i + 1 

    else: 
     if len(theseKeys[i]) == 1: 
      # we only have 1 char so should be a normal key, 
      # otherwise it might be 'ctrl' or similar so ignore it 
      if shift_flag: 
       inputText += chr(ord(theseKeys[i]) - ord(' ')) 
       shift_flag = False 
      else: 
       inputText += theseKeys[i] 

     i = i + 1 

結束例行:

# let's store the final text string into the results finle... 
thisExp.addData('inputText', inputText) 
inputText="" 

在數據文件夾中的結果文件給出的各個鍵用作壓以及最後的字符串

希望代碼是不言自明的。唯一可能不明顯的是,ASCII中較低的大寫字符是1:1 & 32,這是單個空白的值(例如1)。在ASCII「A」 =「A」 +「」)

隨意評論/改善它(它不處理檔位鎖定在目前但應該是很容易解決)

會很高興將它放入庫中,以便「每幀」選項卡上的所有代碼都可以換成一行

+0

Upvote for use(and show showing me)'continueRoutine = False' – Novak 2014-12-05 02:38:37

相關問題