Debian Codegraph @

docs/manual/Demo_window_2__Getting_user_input.html

raw
1 <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 <title>Demo window 2. Getting user input</title>
3 <style>
4 td { padding-left: 5pt; padding-right: 5pt; }
5 th { padding-left: 5pt; padding-right: 5pt; }
6 code { white-space: pre-wrap; }
7 dd { white-space: pre-wrap; }
8 </style>
9 </head><body bgcolor="#FFFFFF">
10
11 <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b>
12 Demo window 2. Getting user input
13 </b></font></table></table>
14 <p>For almost all applications, you will want the user (or the participant in an experiment) to be able to click on things in the Demo window, or to control the Demo window by pressing keys. Here is a presentation with two screens:</p>
15 <code> <a href="_demo_.html">demo</a> <a href="Erase_all.html">Erase all</a><br></code>
16 <code> <a href="_demo_.html">demo</a> <a href="Select_inner_viewport___.html">Select inner viewport:</a> 0, 100, 0, 100<br></code>
17 <code> <a href="_demo_.html">demo</a> <a href="Axes___.html">Axes:</a> 0, 100, 0, 100<br></code>
18 <code> <a href="_demo_.html">demo</a> <a href="Paint_rectangle___.html">Paint rectangle:</a> “purple”, 0, 100, 0, 100<br></code>
19 <code> <a href="_demo_.html">demo</a> <a href="Pink.html">Pink</a><br></code>
20 <code> <a href="_demo_.html">demo</a> <a href="Text___.html">Text:</a> 50, “centre”, 50, “half”, “This is the first page”<br></code>
21 <code> <a href="_demoWaitForInput_.html">demoWaitForInput</a> ()<br></code>
22 <code> <a href="_demo_.html">demo</a> <a href="Erase_all.html">Erase all</a><br></code>
23 <code> <a href="_demo_.html">demo</a> <a href="Paint_rectangle___.html">Paint rectangle:</a> “purple”, 0, 100, 0, 100<br></code>
24 <code> <a href="_demo_.html">demo</a> <a href="Text___.html">Text:</a> 50, “centre”, 50, “half”, “This is the second page”<br></code>
25 <p>In this example, you go from the first to the second screen either by clicking with the mouse or by pressing any key. You will usually want to be more selective in your choice of user actions to respond to. The function <a href="_demoWaitForInput_.html"><b><code><font size=+1>demoWaitForInput</font></code></b></a> always returns 1, so that you can use it nicely in a loop, in which you can react selectively:</p>
26 <code> <a href="_label_.html">label</a> FIRST_SCREEN<br></code>
27 <code> <a href="_demo_.html">demo</a> <a href="Erase_all.html">Erase all</a><br></code>
28 <code> <a href="_demo_.html">demo</a> <a href="Black.html">Black</a><br></code>
29 <code> <a href="_demo_.html">demo</a> <a href="Times.html">Times</a><br></code>
30 <code> <a href="_demo_.html">demo</a> <a href="24.html">24</a><br></code>
31 <code> <a href="_demo_.html">demo</a> <a href="Select_inner_viewport___.html">Select inner viewport:</a> 0, 100, 0, 100<br></code>
32 <code> <a href="_demo_.html">demo</a> <a href="Axes___.html">Axes:</a> 0, 100, 0, 100<br></code>
33 <code> <a href="_demo_.html">demo</a> <a href="Paint_rectangle___.html">Paint rectangle:</a> “purple”, 0, 100, 0, 100<br></code>
34 <code> <a href="_demo_.html">demo</a> <a href="Pink.html">Pink</a><br></code>
35 <code> <a href="_demo_.html">demo</a> <a href="Text___.html">Text:</a> 50, “centre”, 50, “half”, “This is the first page”<br></code>
36 <code> while <b><a href="_demoWaitForInput_.html">demoWaitForInput</a></b> ()<br></code>
37 <code> if <a href="_demoClicked_.html">demoClicked</a> ()<br></code>
38 <code> goto SECOND_SCREEN<br></code>
39 <code> elsif <a href="_demoKeyPressed_.html">demoKeyPressed</a> ()<br></code>
40 <code> if <a href="_demoKey-S_.html">demoKey$</a> () = “→” or <a href="_demoKey-S_.html">demoKey$</a> () = “ ”<br></code>
41 <code> goto SECOND_SCREEN<br></code>
42 <code> endif<br></code>
43 <code> endif<br></code>
44 <code> endwhile<br></code>
45 <code> <a href="_label_.html">label</a> SECOND_SCREEN<br></code>
46 <code> <a href="_demo_.html">demo</a> <a href="Erase_all.html">Erase all</a><br></code>
47 <code> <a href="_demo_.html">demo</a> <a href="Paint_rectangle___.html">Paint rectangle:</a> “purple”, 0, 100, 0, 100<br></code>
48 <code> <a href="_demo_.html">demo</a> <a href="Text___.html">Text:</a> 50, “centre”, 50, “half”, “This is the second page”<br></code>
49 <code> while <b><a href="_demoWaitForInput_.html">demoWaitForInput</a></b> ()<br></code>
50 <code> if <a href="_demoClicked_.html">demoClicked</a> ()<br></code>
51 <code> goto END<br></code>
52 <code> elsif <a href="_demoKeyPressed_.html">demoKeyPressed</a> ()<br></code>
53 <code> if <a href="_demoKey-S_.html">demoKey$</a> () = “←”<br></code>
54 <code> goto FIRST_SCREEN<br></code>
55 <code> elsif <a href="_demoKey-S_.html">demoKey$</a> () = “→” or <a href="_demoKey-S_.html">demoKey$</a> () = “ ”<br></code>
56 <code> goto END<br></code>
57 <code> endif<br></code>
58 <code> endif<br></code>
59 <code> endwhile<br></code>
60 <code> <a href="_label_.html">label</a> END<br></code>
61 <p>This script allows you to use the arrow keys and the space bar to navigate between the two screens. A shorter version is:</p>
62 <code> <a href="_label_.html">label</a> FIRST_SCREEN<br></code>
63 <code> <b><a href="_demo_.html">demo</a></b> <a href="Erase_all.html">Erase all</a><br></code>
64 <code> <b><a href="_demo_.html">demo</a></b> <a href="Black.html">Black</a><br></code>
65 <code> <b><a href="_demo_.html">demo</a></b> <a href="Times.html">Times</a><br></code>
66 <code> <b><a href="_demo_.html">demo</a></b> <a href="24.html">24</a><br></code>
67 <code> <b><a href="_demo_.html">demo</a></b> <a href="Select_inner_viewport___.html">Select inner viewport:</a> 0, 100, 0, 100<br></code>
68 <code> <b><a href="_demo_.html">demo</a></b> <a href="Axes___.html">Axes:</a> 0, 100, 0, 100<br></code>
69 <code> <b><a href="_demo_.html">demo</a></b> <a href="Paint_rectangle___.html">Paint rectangle:</a> "purple", 0, 100, 0, 100<br></code>
70 <code> <b><a href="_demo_.html">demo</a></b> <a href="Pink.html">Pink</a><br></code>
71 <code> <b><a href="_demo_.html">demo</a></b> <a href="Text___.html">Text:</a> 50, "centre", 50, "half", "This is the first page"<br></code>
72 <code> while <b><a href="_demoWaitForInput_.html">demoWaitForInput</a></b> ()<br></code>
73 <code> goto SECOND_SCREEN <b><a href="_demoInput_.html">demoInput</a></b> (“•→ ”)<br></code>
74 <code> endwhile<br></code>
75 <code> <a href="_label_.html">label</a> SECOND_SCREEN<br></code>
76 <code> <b><a href="_demo_.html">demo</a></b> <a href="Erase_all.html">Erase all</a><br></code>
77 <code> <b><a href="_demo_.html">demo</a></b> <a href="Paint_rectangle___.html">Paint rectangle:</a> "purple", 0, 100, 0, 100<br></code>
78 <code> <b><a href="_demo_.html">demo</a></b> <a href="Text___.html">Text:</a> 50, "centre", 50, "half", "This is the second page"<br></code>
79 <code> while <b><a href="_demoWaitForInput_.html">demoWaitForInput</a></b> ()<br></code>
80 <code> goto END <b><a href="_demoInput_.html">demoInput</a></b> (“•→ ”)<br></code>
81 <code> goto FIRST_SCREEN <b><a href="_demoInput_.html">demoInput</a></b> (“←”)<br></code>
82 <code> endwhile<br></code>
83 <code> <a href="_label_.html">label</a> END<br></code>
84 <p>This uses two tricks, namely the possibility of following the <b><code><font size=+1>goto</font></code></b> statement by a condition and using <a href="_demoInput_.html"><b><code><font size=+1>demoInput</font></code></b></a> to quickly test for multiple possible inputs (the bullet represents a mouse click).</p>
85 <h3>Links to this page</h3>
86 <ul>
87 <li><a href="Demo_window.html">Demo window</a>
88 </ul>
89 <hr>
90 <address>
91 <p>© Paul Boersma 2009–2023,2026</p>
92 </address>
93 </body>
94 </html>