source: MML/trunk/applications/doc_html/applications/common/getkey.html @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 6.9 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2                "http://www.w3.org/TR/REC-html40/loose.dtd">
3<html>
4<head>
5  <title>Description of getkey</title>
6  <meta name="keywords" content="getkey">
7  <meta name="description" content="GETKEY - get a single keypress">
8  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
10  <meta name="robots" content="index, follow">
11  <link type="text/css" rel="stylesheet" href="../../m2html.css">
12</head>
13<body>
14<a name="_top"></a>
15<div><a href="../../index.html">Home</a> &gt;  <a href="#">applications</a> &gt; <a href="index.html">common</a> &gt; getkey.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for applications/common&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->
19
20<h1>getkey
21</h1>
22
23<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
24<div class="box"><strong>GETKEY - get a single keypress</strong></div>
25
26<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
27<div class="box"><strong>function ch = getkey(m) </strong></div>
28
29<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
30<div class="fragment"><pre class="comment"> GETKEY - get a single keypress
31   CH = GETKEY waits for a keypress and returns the ASCII code. Accepts
32   all ascii characters, including backspace (8), space (32), enter (13),
33   etc, that can be typed on the keyboard. CH is a double.
34
35   CH = GETKEY('non-ascii') uses non-documented matlab 6.5 features to
36   return a string describing the key pressed so keys like ctrl, alt, tab
37   etc. can also be used. CH is a string.
38
39   This function is kind of a workaround for getch in C. It uses a modal, but
40   non-visible window, which does show up in the taskbar.
41   C-language keywords: KBHIT, KEYPRESS, GETKEY, GETCH
42
43   Examples:
44
45    fprintf('\nPress any key: ') ;
46    ch = getkey ;
47    fprintf('%c\n',ch) ;
48
49    fprintf('\nPress the Ctrl-key: ') ;
50    if strcmp(getkey('non-ascii'),'control'),
51      fprintf('OK\n') ;
52    else
53      fprintf(' ... wrong key ...\n') ;
54    end
55
56  See also INPUT, CHAR</pre></div>
57
58<!-- crossreference -->
59<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
60This function calls:
61<ul style="list-style-image:url(../../matlabicon.gif)">
62</ul>
63This function is called by:
64<ul style="list-style-image:url(../../matlabicon.gif)">
65</ul>
66<!-- crossreference -->
67
68
69<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
70<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function ch = getkey(m) </a>
710002
720003 <span class="comment">% GETKEY - get a single keypress</span>
730004 <span class="comment">%   CH = GETKEY waits for a keypress and returns the ASCII code. Accepts</span>
740005 <span class="comment">%   all ascii characters, including backspace (8), space (32), enter (13),</span>
750006 <span class="comment">%   etc, that can be typed on the keyboard. CH is a double.</span>
760007 <span class="comment">%</span>
770008 <span class="comment">%   CH = GETKEY('non-ascii') uses non-documented matlab 6.5 features to</span>
780009 <span class="comment">%   return a string describing the key pressed so keys like ctrl, alt, tab</span>
790010 <span class="comment">%   etc. can also be used. CH is a string.</span>
800011 <span class="comment">%</span>
810012 <span class="comment">%   This function is kind of a workaround for getch in C. It uses a modal, but</span>
820013 <span class="comment">%   non-visible window, which does show up in the taskbar.</span>
830014 <span class="comment">%   C-language keywords: KBHIT, KEYPRESS, GETKEY, GETCH</span>
840015 <span class="comment">%</span>
850016 <span class="comment">%   Examples:</span>
860017 <span class="comment">%</span>
870018 <span class="comment">%    fprintf('\nPress any key: ') ;</span>
880019 <span class="comment">%    ch = getkey ;</span>
890020 <span class="comment">%    fprintf('%c\n',ch) ;</span>
900021 <span class="comment">%</span>
910022 <span class="comment">%    fprintf('\nPress the Ctrl-key: ') ;</span>
920023 <span class="comment">%    if strcmp(getkey('non-ascii'),'control'),</span>
930024 <span class="comment">%      fprintf('OK\n') ;</span>
940025 <span class="comment">%    else</span>
950026 <span class="comment">%      fprintf(' ... wrong key ...\n') ;</span>
960027 <span class="comment">%    end</span>
970028 <span class="comment">%</span>
980029 <span class="comment">%  See also INPUT, CHAR</span>
990030
1000031 <span class="comment">% (c) 2005 Jos</span>
1010032 <span class="comment">% email jos @ jasen .nl</span>
1020033 <span class="comment">% Feel free to (ab)use, modify or change this contribution</span>
1030034
1040035
1050036 <span class="comment">% Determine the callback string to use</span>
1060037 <span class="keyword">if</span> nargin == 1,
1070038     <span class="keyword">if</span> strcmp(lower(m),<span class="string">'non-ascii'</span>),
1080039         callstr = [<span class="string">'set(gcbf,''Userdata'',get(gcbf,''Currentkey'')) ; uiresume '</span>] ;
1090040     <span class="keyword">else</span>       
1100041         error(<span class="string">'Argument should be the string ''non-ascii'''</span>) ;
1110042     <span class="keyword">end</span>
1120043 <span class="keyword">else</span>
1130044     callstr = [<span class="string">'set(gcbf,''Userdata'',double(get(gcbf,''Currentcharacter''))) ; uiresume '</span>] ;
1140045 <span class="keyword">end</span>
1150046
1160047 <span class="comment">% Set up the figure</span>
1170048 <span class="comment">% May be the position property  should be individually tweaked to avoid visibility</span>
1180049 fh = figure(<span class="string">'keypressfcn'</span>,callstr, <span class="keyword">...</span>
1190050     <span class="string">'windowstyle'</span>,<span class="string">'modal'</span>,<span class="keyword">...</span><span class="comment">    </span>
1200051     <span class="string">'position'</span>,[0 0 1 1],<span class="keyword">...</span>
1210052     <span class="string">'Name'</span>,<span class="string">'GETKEY'</span>, <span class="keyword">...</span>
1220053     <span class="string">'userdata'</span>,<span class="string">'timeout'</span>) ;
1230054 <span class="keyword">try</span>
1240055     <span class="comment">% Wait for something to happen</span>
1250056     uiwait ;
1260057     ch = get(fh,<span class="string">'Userdata'</span>) ;
1270058 <span class="keyword">catch</span>
1280059     <span class="comment">% Something went wrong, return and empty matrix.</span>
1290060     ch = [] ;
1300061 <span class="keyword">end</span>
1310062 close(fh) ;</pre></div>
132<hr><address>Generated on Mon 21-May-2007 15:32:41 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
133</body>
134</html>
Note: See TracBrowser for help on using the repository browser.