File: keyboard.html

package info (click to toggle)
python-visual 3.2.9-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,796 kB
  • ctags: 2,664
  • sloc: cpp: 11,958; sh: 8,185; python: 3,709; ansic: 480; makefile: 311
file content (151 lines) | stat: -rw-r--r-- 5,770 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML>

<HEAD>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">

<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

<META NAME="GENERATOR" CONTENT="Adobe FrameMaker 5.5/HTML Export Filter">

<LINK REL="STYLESHEET" HREF="VisualRef.css" CHARSET="ISO-8859-1" TYPE="text/css">

<TITLE> Description of Objects in VPython</TITLE>

</HEAD>

<BODY BGCOLOR="#ffffff">

<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">

<tr>

      <td><A HREF="mouse.html"><img src="icons/previous.gif" border="0" height="32"

  alt="Previous Page" width="32"></A></td>

      <td><A HREF="index.html"><img src="icons/up.gif" border="0" height="32"

  alt="Up One Level" width="32"></A></td>

      <td><A HREF="controls.html"><img src="icons/next.gif" border="0" height="32"

  alt="Next Page" width="32"></A></td>

<td align="center" width="100%">Visual Reference</td>

      <td><A HREF="index.html"><img src="icons/contents.gif" border="0" height="32"

  alt="Contents" width="32"></A></td>

      <td><img src="icons/blank.gif" border="0" height="32"

  alt="" width="32"></td>

      <td><img src="icons/blank.gif" border="0" height="32"

  alt="" width="32"></td>

</tr></table>

  <b class="navlabel">Previous:</b> <a class="sectref" HREF="mouse.html">Mouse 
  Interactions</A> <b class="navlabel">Up:</b> <a class="sectref" HREF="index.html">Contents</A> 
  <b class="navlabel">Next:</b> <a class="sectref" HREF="controls.html">Controls</A> 
  <br>
  <hr>

</DIV>

<DIV>

  <H1 CLASS="Heading-1"> <font color="#0000A0">Keyboard Interactions</font></H1>

</DIV>

<DIV>
  <P CLASS="Normal">If<span class="attribute"> scene.kb.keys</span> is nonzero, 
    one or more keyboard events have been stored, waiting to be processed.</P>
  <P CLASS="Normal">Executing <span class="attribute">key</span> <span class="attribute">=</span> 
    <span class="attribute">scene.kb.getkey()</span> obtains a keyboard input 
    and removes it from the input queue. If there are no events waiting to be 
    processed, getkey() waits until a key is pressed.</P>
  <P CLASS="Normal">If len(key) == 1, the input is a single printable character 
    such as 'b' or 'B' or new line ('\n') or tab ('\t'). Otherwise key is a multicharacter 
    string such as 'escape' or 'backspace' or 'f3'. For such inputs, the ctrl, 
    alt, and shift keys are prepended to the key name. For example, if you hold 
    down the shift key and press F3, key will be the character string 'shift+f3', 
    which you can test for explicitly. If you hold down all three modifier keys, 
    you get 'ctrl+alt+shift+f3'; the order is always ctrl, alt, shift.</P>
  <P CLASS="Normal">Here is a test routine that let's you type text into a label:</P>
  <P CLASS="Normal">&nbsp;</P>
  <p class="program"><span class="program">prose = label() # initially blank text</span></p>
  <p class="program">while 1: </p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;if scene.kb.keys: # is there an event 
    waiting to be processed?</p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="program">s 
    = scene.kb.getkey() # obtain keyboard information</span></p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="program">if 
    len(s) == 1:</span> </p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="program">prose.text 
    += s # append new character</span></p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="program">elif 
    (s == 'backspace' or s == 'delete') and len(prose.text) > 0: </span> </p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="program">prose.text 
    = prose.text[:-1] # erase one letter</span></p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="program">elif 
    s == 'shift+delete':</span> </p>
  <p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="program">prose.text 
    = '' # erase all the text</span></p>
  <p class="program">&nbsp;</p>
  <P CLASS="Normal">Note that <a href="mouse.html">mouse events</a> also provide 
    information about the ctrl, alt, and shift keys, which may be used to modify 
    mouse actions.</P>
  <DIV>
<P CLASS="Normal">&nbsp; </P>
  </DIV>
</DIV>

<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">

<tr>

      <td><A HREF="mouse.html"><img src="icons/previous.gif" border="0" height="32"

  alt="Previous Page" width="32"></A></td>

      <td><A HREF="index.html"><img src="icons/up.gif" border="0" height="32"

  alt="Up One Level" width="32"></A></td>

      <td><A HREF="controls.html"><img src="icons/next.gif" border="0" height="32"

  alt="Next Page" width="32"></A></td>

<td align="center" width="100%">Visual Reference</td>

      <td><A HREF="index.html"><img src="icons/contents.gif" border="0" height="32"

  alt="Contents" width="32"></A></td>

      <td><img src="icons/blank.gif" border="0" height="32"

  alt="" width="32"></td>

      <td><img src="icons/blank.gif" border="0" height="32"

  alt="" width="32"></td>

</tr></table>

  <b class="navlabel">Previous:</b> <a class="sectref" href="mouse.html">Mouse 
  Interactions</a> <b class="navlabel">Up:</b> <a class="sectref" HREF="index.html">Contents</A> 
  <b class="navlabel">Next:</b> <a class="sectref" href="controls.html">Controls</a> 
  <br>
  <hr>

</DIV>

</BODY>

</HTML>