-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path1015.html
More file actions
382 lines (382 loc) · 33.4 KB
/
Copy path1015.html
File metadata and controls
382 lines (382 loc) · 33.4 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | DEFINEKEY</title>
<meta name="description" content="Binds a keystroke to a user defined function">
<link rel="canonical" href="1015">
<link rel="keywords" href="DEFINEKEY k,sub">
<link rel="stylesheet" href="/css/style.css">
<link rel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<script src="/clipboard.js"></script>
</head>
<body>
<button onclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<script src="/backtotop.js"></script>
<div class="wrapAll clearfix">
<nav class="navigation">
<div class="logo">
<a href="/"><img src='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<div class="navlinks">
<a href="/pages/download.html">Download</a>
<a href="/pages/news.html">News</a>
<a href="/pages/community.html">Community</a>
<a href="/pages/articles.html">Resources</a>
<a class='active' href="/pages/reference.html">Language Reference</a>
<a href="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<div class="mainsection">
<div class="tabs clearfix">
<div class="tabsRight">
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/reference/1015-console-definekey.markdown">Edit</a>
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/reference/1015-console-definekey.markdown">History</a>
</div>
</div>
<div class="article">
<h1>DEFINEKEY</h1>
<blockquote>DEFINEKEY k, sub</blockquote>
<div class="siteSub">
<p>
<a href="/">Home</a> >
<a href="/pages/reference.html">Reference</a> >
<a href="/pages/console.html">Console</a>
</p>
</div>
<p>Binds a keycode <code>k</code> to a user defined sub routine
<code>sub</code>. When the key is pressed, the corresponding sub routine
will be called. To unbind the keycode definition pass <code>0</code> as
the <code>sub</code> argument.</p>
<p>Keycodes for PC keyboard</p>
<table>
<thead>
<tr class="header">
<th>Key</th>
<th>Keycode</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>A to Z</td>
<td>asc(“a”) to asc(“z”)</td>
</tr>
<tr class="even">
<td>0 to 9</td>
<td>asc(“0”) to asc(“9”)</td>
</tr>
<tr class="odd">
<td>Backspace</td>
<td>8</td>
</tr>
<tr class="even">
<td>Delete</td>
<td>127</td>
</tr>
<tr class="odd">
<td>Break</td>
<td>3</td>
</tr>
<tr class="even">
<td>Tab</td>
<td>9</td>
</tr>
<tr class="odd">
<td>Enter / Return</td>
<td>13</td>
</tr>
<tr class="even">
<td>Space</td>
<td>32</td>
</tr>
<tr class="odd">
<td>Escape</td>
<td>27</td>
</tr>
<tr class="even">
<td>Page Up / Prior</td>
<td>0xFF01</td>
</tr>
<tr class="odd">
<td>Page Down / Next</td>
<td>0xFF02</td>
</tr>
<tr class="even">
<td>Left</td>
<td>0xFF04</td>
</tr>
<tr class="odd">
<td>Right</td>
<td>0xFF05</td>
</tr>
<tr class="even">
<td>Up</td>
<td>0xFF09</td>
</tr>
<tr class="odd">
<td>Down</td>
<td>0xFF0A</td>
</tr>
<tr class="even">
<td>Insert</td>
<td>0xFF10</td>
</tr>
<tr class="odd">
<td>Home</td>
<td>0xFF11</td>
</tr>
<tr class="even">
<td>End</td>
<td>0xFF12</td>
</tr>
<tr class="odd">
<td>Menu</td>
<td>0xFF1F</td>
</tr>
<tr class="even">
<td>F1 to F15</td>
<td>0xFFF0+1 to 0xFFF0+15</td>
</tr>
<tr class="odd">
<td>Ctrl + A to Z</td>
<td>0x71000000 + asc(“a”) to 0x71000000 + asc(“z”)</td>
</tr>
<tr class="even">
<td>Alt + A to Z</td>
<td>0x72000000 + asc(“a”) to 0x72000000 + asc(“z”)</td>
</tr>
<tr class="odd">
<td>Shift + A to Z</td>
<td>asc(“A”) to asc(“Z”)</td>
</tr>
</tbody>
</table>
<h3 id="examples">Examples</h3>
<p>Example 1: Bind keystroke for left and right arrow key</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">defineKey</span> <span class="dv">0xFF04</span>, Increase <span class="co">'Left arrow</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="kw">defineKey</span> <span class="dv">0xFF05</span>, Decrease <span class="co">'Right arrow</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>Increase</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> x = x + <span class="dv">1</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>Decrease</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> x = x - <span class="dv">1</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="kw">while(</span><span class="dv">1</span>)</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> t = <span class="fu">ticks</span>()</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">at</span> <span class="dv">0</span>,<span class="dv">0</span>: <span class="kw">print</span> t + <span class="st">": "</span> + x + <span class="st">" "</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">delay</span>(<span class="dv">50</span>)</span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<h3 id="example-2-unbind-a-keystroke">Example 2: Unbind a keystroke</h3>
<div class="sourceCode" id="cb2"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">DEFINEKEY</span> <span class="dv">0xFF04</span>, <span class="dv">0</span></span></code></pre></div>
<h3 id="example-3-etch-a-sketch">Example 3: Etch-a-Sketch</h3>
<div class="sourceCode" id="cb3"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">' DEFINEKEY demo.bas SmallBASIC 0.12.2 [B+=MGA] 2016-03-30</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co">'remember Etch-A-Sketch?</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co">'definekey key,sub</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="co">'example: </span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="kw">definekey</span> <span class="dv">0xFF04</span>, moveleft <span class="co">'press left arrow</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="kw">definekey</span> <span class="dv">0xFF05</span>, moveright <span class="co">'press right arrow</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="kw">definekey</span> <span class="dv">0xFF09</span>, moveup <span class="co">'press up arror</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="kw">definekey</span> <span class="dv">0xFF0A</span>, movedown <span class="co">'press down arrow</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="kw">definekey</span> <span class="dv">99</span>, togglecolor <span class="co">'press c for color toggle black (erase), blue, red, white</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a><span class="kw">definekey</span> <span class="dv">115</span>, togglestepper <span class="co">'press s for stepper 1,5,10,50</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="kw">definekey</span> <span class="dv">27</span>, quit <span class="co">'press esc to quit</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a>colr=<span class="dv">15</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a>stepper=<span class="dv">1</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a>tx=<span class="dt">xmax</span>/<span class="dv">2</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a>ty=<span class="dt">ymax</span>/<span class="dv">2</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a><span class="fu">pset</span> tx,ty,<span class="dv">0</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">color</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a> <span class="fu">locate</span> <span class="dv">0</span>,<span class="dv">0</span>:? <span class="fu">spc</span>(<span class="dv">100</span>)</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">color</span> colr,<span class="dv">0</span></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a> <span class="fu">locate</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>colr=<span class="dv">0</span> <span class="kw">then co</span>lor colr,<span class="dv">15</span></span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a> ?<span class="st">"tx= "</span>;tx;<span class="st">" ty= "</span>;ty;<span class="st">" c= "</span>;colr;<span class="st">" s="</span>;stepper;</span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>colr=<span class="dv">0</span> <span class="kw">then co</span>lor colr,<span class="dv">0</span></span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a> lc=(lc+<span class="dv">1</span>) <span class="kw">mod</span> <span class="dv">2</span></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>lc <span class="kw">then ps</span>et step <span class="dv">0</span>,<span class="dv">0</span>,<span class="dv">14</span> <span class="kw">else</span> <span class="fu">pset</span> step <span class="dv">0</span>,<span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a> <span class="fu">delay</span> <span class="dv">60</span></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>moveleft</span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a> <span class="fu">pset</span> step <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>tx-stepper>=<span class="dv">0</span> <span class="kw">then tx</span>-=stepper:<span class="fu">line</span> step -stepper,<span class="dv">0</span> <span class="kw">else</span> <span class="fu">beep</span></span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>moveright</span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true" tabindex="-1"></a> <span class="fu">pset</span> step <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>tx+stepper<=<span class="dt">xmax</span> <span class="kw">then tx</span>+=stepper:<span class="fu">line</span> step stepper,<span class="dv">0</span> <span class="kw">else</span> <span class="fu">beep</span></span>
<span id="cb3-36"><a href="#cb3-36" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb3-37"><a href="#cb3-37" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>moveup</span>
<span id="cb3-38"><a href="#cb3-38" aria-hidden="true" tabindex="-1"></a> <span class="fu">pset</span> step <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-39"><a href="#cb3-39" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>ty-stepper>=<span class="dv">0</span> <span class="kw">then ty</span>-=stepper:<span class="fu">line</span> step <span class="dv">0</span>,-stepper <span class="kw">else</span> <span class="fu">beep</span></span>
<span id="cb3-40"><a href="#cb3-40" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb3-41"><a href="#cb3-41" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>movedown</span>
<span id="cb3-42"><a href="#cb3-42" aria-hidden="true" tabindex="-1"></a> <span class="fu">pset</span> step <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-43"><a href="#cb3-43" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>ty+stepper<=<span class="dt">ymax</span> <span class="kw">then ty</span>+=stepper:<span class="fu">line</span> step <span class="dv">0</span>,stepper <span class="kw">else</span> <span class="fu">beep</span></span>
<span id="cb3-44"><a href="#cb3-44" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb3-45"><a href="#cb3-45" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>togglecolor</span>
<span id="cb3-46"><a href="#cb3-46" aria-hidden="true" tabindex="-1"></a> <span class="kw">select case </span>colr</span>
<span id="cb3-47"><a href="#cb3-47" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">0</span> : colr=<span class="dv">9</span></span>
<span id="cb3-48"><a href="#cb3-48" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">9</span> : colr=<span class="dv">12</span></span>
<span id="cb3-49"><a href="#cb3-49" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">12</span>: colr=<span class="dv">15</span></span>
<span id="cb3-50"><a href="#cb3-50" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">15</span>: colr=<span class="dv">0</span></span>
<span id="cb3-51"><a href="#cb3-51" aria-hidden="true" tabindex="-1"></a> <span class="kw">end select</span></span>
<span id="cb3-52"><a href="#cb3-52" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb3-53"><a href="#cb3-53" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>togglestepper</span>
<span id="cb3-54"><a href="#cb3-54" aria-hidden="true" tabindex="-1"></a> <span class="kw">select case </span>stepper</span>
<span id="cb3-55"><a href="#cb3-55" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">1</span> : stepper=<span class="dv">5</span></span>
<span id="cb3-56"><a href="#cb3-56" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">5</span> : stepper=<span class="dv">10</span></span>
<span id="cb3-57"><a href="#cb3-57" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">10</span>: stepper=<span class="dv">50</span></span>
<span id="cb3-58"><a href="#cb3-58" aria-hidden="true" tabindex="-1"></a> <span class="kw">case</span> <span class="dv">50</span>: stepper=<span class="dv">1</span></span>
<span id="cb3-59"><a href="#cb3-59" aria-hidden="true" tabindex="-1"></a> <span class="kw">end select</span></span>
<span id="cb3-60"><a href="#cb3-60" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb3-61"><a href="#cb3-61" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>quit</span>
<span id="cb3-62"><a href="#cb3-62" aria-hidden="true" tabindex="-1"></a> <span class="kw">stop</span></span>
<span id="cb3-63"><a href="#cb3-63" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code></pre></div>
<h3
id="example-4-this-example-is-outdated-and-just-a-reference-for-buttons-in-palm-os">Example
4: This example is outdated and just a reference for buttons in PALM
OS</h3>
<div class="sourceCode" id="cb4"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co">' Note:</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="co">' * You may Include "definekey_const.bas" file in another file to make your code more clear.</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co">'</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="co">' * Created using SmallBASIC version 0.12.2 (on Linux Mint 17.3).</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="co">' * More keys might be included in future/other versions of SmallBASIC.</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a><span class="co">' * Values for DEFINEKEY cannot be used for INKEY.</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a><span class="co">' * I could not verify all keys (especially CTRL & ALT seems not to work).</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a><span class="co">' * Key codes are from "keymap.h": https://sourceforge.net/p/smallbasic/code/HEAD/tree/trunk/smallbasic/src/keymap.h</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a><span class="co">'</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a><span class="co">' Demo - add these lines to another BAS file:</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a><span class="co">' ------------------------------------------</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a><span class="co">' Include "definekey_const.bas"</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a><span class="co">'</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a><span class="co">' Definekey DK_LEFT, left_arrow</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a><span class="co">'</span></span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a><span class="co">' Sub left_arrow: i++: ? i; " ";</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a><span class="co">' End Sub</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a><span class="co">'</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a><span class="co">' ? "Press Left-Arrow key, or Ctrl+B to stop...": Pause</span></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a><span class="co">' While 1: Wend</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a><span class="co">' ------------------------------------------</span></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a><span class="co">' definekey_const.bas - DEFINEKEY key codes (keymap.h; 30/4/2010)</span></span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a><span class="co">' Note: bind a regular character with 'DEFINEKEY Asc("a"), sub'</span></span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> IS_PALM_OS = (<span class="fu">Left</span>(OSNAME, <span class="dv">1</span>) = <span class="st">"P"</span>) <span class="co">' Else is_UNIX / is_Windows</span></span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a><span class="co">' PalmOS - H/W keys:</span></span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_PGUP = <span class="dv">0xFF01</span></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_PGDN = <span class="dv">0xFF02</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_BTN1 = <span class="dv">0xFF03</span></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_BTN2 = <span class="dv">0xFF04</span></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_BTN3 = <span class="dv">0xFF05</span></span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_BTN4 = <span class="dv">0xFF06</span></span>
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_FIND = <span class="dv">0xFF07</span></span>
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PALM_CALC = <span class="dv">0xFF08</span></span>
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_BREAK = <span class="kw">Iff</span>(IS_PALM_OS, DK_PALM_BTN4, <span class="dv">0x3</span>) <span class="co">' MemoPad, Ctrl+C</span></span>
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_DELETE = <span class="dv">127</span> <span class="co">' (in keymap.h: DELETE = 8, BACKSPACE = 127)</span></span>
<span id="cb4-36"><a href="#cb4-36" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_BACKSPACE = <span class="dv">8</span></span>
<span id="cb4-37"><a href="#cb4-37" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_TAB = <span class="dv">9</span></span>
<span id="cb4-38"><a href="#cb4-38" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_ENTER = <span class="dv">13</span> <span class="co">' 13 is CR (in keymap.h: ENTER = '\\n')</span></span>
<span id="cb4-39"><a href="#cb4-39" aria-hidden="true" tabindex="-1"></a><span class="co">' Common with Handhelds (0xFF00 to 0xFF0F):</span></span>
<span id="cb4-40"><a href="#cb4-40" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PGUP = <span class="dv">0xFF01</span></span>
<span id="cb4-41"><a href="#cb4-41" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PRIOR = DK_PGUP</span>
<span id="cb4-42"><a href="#cb4-42" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_PGDN = <span class="dv">0xFF02</span></span>
<span id="cb4-43"><a href="#cb4-43" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_NEXT = DK_PGDN</span>
<span id="cb4-44"><a href="#cb4-44" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_LEFT = <span class="dv">0xFF04</span></span>
<span id="cb4-45"><a href="#cb4-45" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_RIGHT = <span class="dv">0xFF05</span></span>
<span id="cb4-46"><a href="#cb4-46" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_UP = <span class="dv">0xFF09</span></span>
<span id="cb4-47"><a href="#cb4-47" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_DN = <span class="dv">0xFF0A</span></span>
<span id="cb4-48"><a href="#cb4-48" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_DOWN = DK_DN</span>
<span id="cb4-49"><a href="#cb4-49" aria-hidden="true" tabindex="-1"></a><span class="co">' Common on PCs (0xFF10 to 0xFF1F):</span></span>
<span id="cb4-50"><a href="#cb4-50" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_INSERT = <span class="dv">0xFF10</span></span>
<span id="cb4-51"><a href="#cb4-51" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_HOME = <span class="dv">0xFF11</span></span>
<span id="cb4-52"><a href="#cb4-52" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_END = <span class="dv">0xFF12</span></span>
<span id="cb4-53"><a href="#cb4-53" aria-hidden="true" tabindex="-1"></a><span class="co">' Other application keys:</span></span>
<span id="cb4-54"><a href="#cb4-54" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MENU = <span class="dv">0xFF1F</span></span>
<span id="cb4-55"><a href="#cb4-55" aria-hidden="true" tabindex="-1"></a><span class="co">' Function keys (16 codes), e.g. Definekey DK_FUNC(1):</span></span>
<span id="cb4-56"><a href="#cb4-56" aria-hidden="true" tabindex="-1"></a><span class="kw">Def</span> DK_FUNC(x) = <span class="dv">0xFFF0</span> + x <span class="co">' -- Verified with 1-12 (F1-F12)</span></span>
<span id="cb4-57"><a href="#cb4-57" aria-hidden="true" tabindex="-1"></a><span class="kw">Def</span> DK_SFUNC(x) = <span class="dv">0xFFE0</span> + x <span class="co">' ( ...is it for F13-F16 ? )</span></span>
<span id="cb4-58"><a href="#cb4-58" aria-hidden="true" tabindex="-1"></a><span class="co">' Control keys, e.g. Definekey DK_CTRL(ASC("R")):</span></span>
<span id="cb4-59"><a href="#cb4-59" aria-hidden="true" tabindex="-1"></a><span class="kw">Def</span> DK_CTRL(x) = x - <span class="dv">64</span> <span class="co">' x must be a capital character</span></span>
<span id="cb4-60"><a href="#cb4-60" aria-hidden="true" tabindex="-1"></a><span class="co">' Alt keys, e.g. Definekey DK_ALT(ASC("r")):</span></span>
<span id="cb4-61"><a href="#cb4-61" aria-hidden="true" tabindex="-1"></a><span class="kw">Def</span> DK_ALT(x) = <span class="dv">0xFF20</span> + (x - <span class="kw">Iff</span>(x >= <span class="dv">97</span>, <span class="dv">57</span>, <span class="dv">31</span>))</span>
<span id="cb4-62"><a href="#cb4-62" aria-hidden="true" tabindex="-1"></a><span class="co">' Keypad:</span></span>
<span id="cb4-63"><a href="#cb4-63" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_DIV = <span class="dv">0xFFDA</span></span>
<span id="cb4-64"><a href="#cb4-64" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_MUL = <span class="dv">0xFFDB</span></span>
<span id="cb4-65"><a href="#cb4-65" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_MINUS = <span class="dv">0xFFDC</span></span>
<span id="cb4-66"><a href="#cb4-66" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_PLUS = <span class="dv">0xFFDD</span></span>
<span id="cb4-67"><a href="#cb4-67" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_ENTER = <span class="dv">0xFFDE</span></span>
<span id="cb4-68"><a href="#cb4-68" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_HOME = <span class="dv">0xFFD7</span></span>
<span id="cb4-69"><a href="#cb4-69" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_UP = <span class="dv">0xFFD8</span></span>
<span id="cb4-70"><a href="#cb4-70" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_PGUP = <span class="dv">0xFFD9</span></span>
<span id="cb4-71"><a href="#cb4-71" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_LEFT = <span class="dv">0xFFD4</span></span>
<span id="cb4-72"><a href="#cb4-72" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_CENTER = <span class="dv">0xFFD5</span></span>
<span id="cb4-73"><a href="#cb4-73" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_RIGHT = <span class="dv">0xFFD6</span></span>
<span id="cb4-74"><a href="#cb4-74" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_END = <span class="dv">0xFFD1</span></span>
<span id="cb4-75"><a href="#cb4-75" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_DOWN = <span class="dv">0xFFD2</span></span>
<span id="cb4-76"><a href="#cb4-76" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_PGDN = <span class="dv">0xFFD3</span></span>
<span id="cb4-77"><a href="#cb4-77" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_INS = <span class="dv">0xFFD0</span></span>
<span id="cb4-78"><a href="#cb4-78" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_KP_DEL = <span class="dv">0xFFDF</span></span>
<span id="cb4-79"><a href="#cb4-79" aria-hidden="true" tabindex="-1"></a><span class="co">' Mouse:</span></span>
<span id="cb4-80"><a href="#cb4-80" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MK_PUSH = <span class="dv">0xFFC0</span></span>
<span id="cb4-81"><a href="#cb4-81" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MK_DRAG = <span class="dv">0xFFC1</span></span>
<span id="cb4-82"><a href="#cb4-82" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MK_MOVE = <span class="dv">0xFFC2</span></span>
<span id="cb4-83"><a href="#cb4-83" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MK_RELEASE = <span class="dv">0xFFC3</span></span>
<span id="cb4-84"><a href="#cb4-84" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MK_WHEEL = <span class="dv">0xFFC4</span></span>
<span id="cb4-85"><a href="#cb4-85" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MK_FIRST = DK_MK_PUSH</span>
<span id="cb4-86"><a href="#cb4-86" aria-hidden="true" tabindex="-1"></a><span class="dt">Const</span> DK_MK_LAST = DK_MK_WHEEL</span></code></pre></div>
<div class="lavenderBox">
<div class="header">Code samples using DEFINEKEY</div>
<div class="linklist">
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 2/falling blocks - tetris.bas">falling blocks - tetris.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 3/lander.bas">lander.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 3/raycaster.bas">raycaster.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 4/raycaster.bas">raycaster.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 4/shooter.bas">shooter.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 4/snake.bas">snake.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 2/space shooter.bas">space shooter.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 3/tetris.bas">tetris.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 4/water.bas">water.bas </a>
</div>
</div>
<div class="lavenderBox">
<div class="header">Console</div>
<div class="linklist">
<a href="/reference/521.html">AT </a>
<a href="/reference/522.html">BEEP </a>
<a href="/reference/538.html">CAT </a>
<a href="/reference/524.html">CLS </a>
<a href="/reference/1015.html"><strong>DEFINEKEY</strong> </a>
<a href="/reference/525.html">FORM </a>
<a href="/reference/539.html">INKEY </a>
<a href="/reference/527.html">INPUT </a>
<a href="/reference/528.html">LINEINPUT </a>
<a href="/reference/529.html">LINPUT </a>
<a href="/reference/530.html">LOCATE </a>
<a href="/reference/531.html">LOGPRINT </a>
<a href="/reference/532.html">NOSOUND </a>
<a href="/reference/533.html">PEN </a>
<a href="/reference/534.html">PLAY </a>
<a href="/reference/535.html">PRINT </a>
<a href="/reference/536.html">SOUND </a>
<a href="/reference/540.html">TAB </a>
</div>
</div>
</div>
<div class="pagefooter">
This page was last edited on Mon, 19 May 2025 20:22:52 +0930
|
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<a href="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>