curs_getch(3x) curs_getch(3x)
getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get
(or push back) characters from curses terminal keyboard
- curses 端末キーボードから文字を取得する (または返却する)
#include <curses.h>
int getch(void);
int wgetch(WINDOW *win);
int mvgetch(int y, int x);
int mvwgetch(WINDOW *win, int y, int x);
int ungetch(int ch);
int has_key(int ch);
The getch, wgetch, mvgetch and mvwgetch, routines read a
character from the window. In no-delay mode, if no input
is waiting, the value ERR is returned. In delay mode, the
program waits until the system passes text through to the
program. Depending on the setting of cbreak, this is af-
ter one character (cbreak mode), or after the first new-
line (nocbreak mode). In half-delay mode, the program
waits until a character is typed or the specified timeout
has been reached.
getch, wgetch, mvgetch, mvwgetch ルーチンはウィンドウ
から文字を読み込みます。
遅延なしモードでは、待っている入力がない場合、ERR 値 を
返します。
遅延モードでは、プログラムはシステムから文字を渡されるまで
待ちます。 これは cbreakの設定により、cbreak モードでは
1 文字の後、nocbreak モードでは最初の改行の後になります。
半遅延モードでは、プログラムは文字がタイプされるか、指定
されたタイムアウトに達するまで待ちます。
If echo is enabled, and the window is not a pad, then the
character will also be echoed into the designated window
according to the following rules:
echo が有効で、かつウィンドウがパッドでない場合、
文字は次の規則にしたがって、指定されたウィンドウへエコーさ
れます。
o If the character is the current erase character, left
arrow, or backspace, the cursor is moved one space to
the left and that screen position is erased as if
delch had been called.
o 文字が現在の erase 文字、左矢印あるいはバックスペースで
ある場合、カーソルは左に 1 桁移動し、その位置はあたかも
delch が呼ばれたかのように削除されます。
o If the character value is any other KEY_ define, the
user is alerted with a beep call.
o 文字の値が他の KEY_ 定義キーである場合、警告として
beep が呼び出されます。
o If the character is a carriage-return, and if nl is
enabled, it is translated to a line-feed after echo-
ing.
o 文字が復帰(キャリッジ・リターン)で、かつ nl が有効な
場合、エコーされた後、改行(ライン・フィード)に
変換されます。
o Otherwise the character is simply output to the
screen.
o それ以外の文字は、単に画面に出力されます。
If the window is not a pad, and it has been moved or modi-
fied since the last call to wrefresh, wrefresh will be
called before another character is read.
ウィンドウがパッドでなく、かつ、最後に wrefresh が
呼び出されて以降に移動または修正された場合、他の文字が読み
込まれる前に wrefresh が呼び出されます。
If keypad is TRUE, and a function key is pressed, the to-
ken for that function key is returned instead of the raw
characters. Possible function keys are defined in <curs-
es.h> as macros with values outside the range of 8-bit
characters whose names begin with KEY_. Thus, a variable
intended to hold the return value of a function key must
be of short size or larger.
keypad が TRUE のとき、ファンクションキーが押されると、
生の文字コードの代わりに、そのファンクションキーのトークンを
返します。
使用可能なファンクションキーは、 <curses.h> の中で、
名前が KEY_ で始まり 8 ビット文字の範囲外の値を持つマクロと
して定義されています。
したがって、ファンクションキーの返り値を入れるための変数は、
short かそれよりも大きくなければなりません。
When a character that could be the beginning of a function
key is received (which, on modern terminals, means an es-
cape character), curses sets a timer. If the remainder of
the sequence does not come in within the designated time,
the character is passed through; otherwise, the function
key value is returned. For this reason, many terminals
experience a delay between the time a user presses the es-
cape key and the escape is returned to the program.
ファンクションキーの始まりとなりうる文字 (現代の端末上では
エスケープ文字を意味します) を受け取ると、 curses はタイマを
セットします。シーケンスの残りが指定された時間内に来ない場合、
文字はそのまま渡されます。そうでなければ、ファンクションキー
の値が返されます。
この理由により、大半の端末では、ユーザがエスケープキーを押
してからプログラムにエスケープが返されるまでに遅れが発生しま
す。
The ungetch routine places ch back onto the input queue to
be returned by the next call to wgetch. There is just one
input queue for all windows.
ungetch ルーチンは、入力キューに ch を戻し、次の wgetch
呼び出しで返されるようにします。
入力キューは全ウィンドウに対してただ 1 つしかありません。
The following special keys are defined in <curses.h>.
次の特殊キーが <curses.h> で定義されています。
o Except for the special case KEY_RESIZE, it is neces-
sary to enable keypad for getch to return these codes.
o KEY_RESIZE による特殊な場合を除くと、 getch が下記の
値を返すためには keypad を有効にする必要があります。
o Not all of these are necessarily supported on any par-
ticular terminal.
o これらのすべてが任意の端末で必ずサポートされるとは
限りません。
o The naming convention may seem obscure, with some ap-
parent misspellings (such as "RSUME" for "resume").
The names correspond to the long terminfo capability
names for the keys, and were defined long ago, in the
1980s.
o 命名規則はわかりにくいかもしれません。resume を RSUME
と綴るスペルミスのようなものもあります。terminfo の長い
名前に対応できるキーの名前は、ずっと以前、1980年代に決
められたものです。
Name Key name
名前 キーの名前
-------------------------------------------------
KEY_BREAK Break key
KEY_BREAK 中断キー
KEY_DOWN The four arrow keys ...
KEY_DOWN 下矢印キー
KEY_UP
KEY_UP 上矢印キー
KEY_LEFT
KEY_LEFT 左矢印キー
KEY_RIGHT
KEY_RIGHT 右矢印キー
KEY_HOME Home key (upward+left arrow)
KEY_HOME ホームキー (上+左矢印)
KEY_BACKSPACE Backspace
KEY_BACKSPACE バックスペース
KEY_F0 Function keys; space for 64 keys
is reserved
KEY_F0 ファンクションキー; 64 キー分の領
域が予約されている
KEY_F(n) For 0 <= n <= 63
KEY_F(n) 0 <= n <= 63
KEY_DL Delete line
KEY_DL 行削除
KEY_IL Insert line
KEY_IL 行挿入
KEY_DC Delete character
KEY_DC 文字削除または抹消文字
KEY_IC Insert char or enter insert mode
KEY_IC 文字挿入、または文字挿入モードへ入る
KEY_EIC Exit insert char mode
KEY_EIC 文字挿入モードを出る
KEY_CLEAR Clear screen
KEY_CLEAR 画面消去
KEY_EOS Clear to end of screen
KEY_EOS 画面の末端まで消去
KEY_EOL Clear to end of line
KEY_EOL 行末まで消去
KEY_SF Scroll 1 line forward
KEY_SF 前に 1 行スクロール
KEY_SR Scroll 1 line backward (reverse)
KEY_SR 後方 (逆) に 1 行スクロール
KEY_NPAGE Next page
KEY_NPAGE 次ページ
KEY_PPAGE Previous page
KEY_PPAGE 前ページ
KEY_STAB Set tab
KEY_STAB タブセット
KEY_CTAB Clear tab
KEY_CTAB タブクリア
KEY_CATAB Clear all tabs
KEY_CATAB 全タブクリア
KEY_ENTER Enter or send
KEY_ENTER 入力または送信
KEY_SRESET Soft (partial) reset
KEY_SRESET ソフト (部分) リセット
KEY_RESET Reset or hard reset
KEY_RESET リセットまたはハードリセット
KEY_PRINT Print or copy
KEY_PRINT プリントまたはコピー
KEY_LL Home down or bottom (lower left)
KEY_LL ホームダウンまたは最下部 (左下)
KEY_A1 Upper left of keypad
KEY_A1 キーパッドの左上
KEY_A3 Upper right of keypad
KEY_A3 キーパッドの右上
KEY_B2 Center of keypad
KEY_B2 キーパッドの中央
KEY_C1 Lower left of keypad
KEY_C1 キーパッドの左下
KEY_C3 Lower right of keypad
KEY_C3 キーパッドの右下
KEY_BTAB Back tab key
KEY_BTAB バックタブキー
KEY_BEG Beg(inning) key
KEY_BEG 開始キー
KEY_CANCEL Cancel key
KEY_CANCEL キャンセルキー
KEY_CLOSE Close key
KEY_CLOSE クローズキー
KEY_COMMAND Cmd (command) key
KEY_COMMAND コマンドキー
KEY_COPY Copy key
KEY_COPY コピーキー
KEY_CREATE Create key
KEY_CREATE クリエイトキー
KEY_END End key
KEY_END エンドキー
KEY_EXIT Exit key
KEY_EXIT 終了キー
KEY_FIND Find key
KEY_FIND 検索キー
KEY_HELP Help key
KEY_HELP ヘルプキー
KEY_MARK Mark key
KEY_MARK マークキー
KEY_MESSAGE Message key
KEY_MESSAGE メッセージキー
KEY_MOUSE Mouse event read
KEY_MOUSE マウスイベント読み込み
KEY_MOVE Move key
KEY_MOVE 移動キー
KEY_NEXT Next object key
KEY_NEXT 次オブジェクトキー
KEY_OPEN Open key
KEY_OPEN オープンキー
KEY_OPTIONS Options key
KEY_OPTIONS オプションキー
KEY_PREVIOUS Previous object key
KEY_PREVIOUS 前オブジェクトキー
KEY_REDO Redo key
KEY_REDO 再実行キー
KEY_REFERENCE Ref(erence) key
KEY_REFERENCE 参照キー
KEY_REFRESH Refresh key
KEY_REFRESH リフレッシュキー
KEY_REPLACE Replace key
KEY_REPLACE 置換キー
KEY_RESIZE Screen resized
KEY_RESIZE 画面リサイズ
KEY_RESTART Restart key
KEY_RESTART リスタートキー
KEY_RESUME Resume key
KEY_RESUME リジュームキー
KEY_SAVE Save key
KEY_SAVE 保存キー
KEY_SBEG Shifted beginning key
KEY_SBEG シフトした開始キー
KEY_SCANCEL Shifted cancel key
KEY_SCANCEL シフトしたキャンセルキー
KEY_SCOMMAND Shifted command key
KEY_SCOMMAND シフトしたコマンドキー
KEY_SCOPY Shifted copy key
KEY_SCOPY シフトしたコピーキー
KEY_SCREATE Shifted create key
KEY_SCREATE シフトしたクリエイトキー
KEY_SDC Shifted delete char key
KEY_SDC シフトした文字削除キー
KEY_SDL Shifted delete line key
KEY_SDL シフトした行削除キー
KEY_SELECT Select key
KEY_SELECT セレクトキー
KEY_SEND Shifted end key
KEY_SEND シフトしたエンドキー
KEY_SEOL Shifted clear line key
KEY_SEOL シフトした行クリアキー
KEY_SEXIT Shifted exit key
KEY_SEXIT シフトした終了キー
KEY_SFIND Shifted find key
KEY_SFIND シフトした検索キー
KEY_SHELP Shifted help key
KEY_SHELP シフトしたヘルプキー
KEY_SHOME Shifted home key
KEY_SHOME シフトしたホームキー
KEY_SIC Shifted input key
KEY_SIC シフトしたインプットキー
KEY_SLEFT Shifted left arrow key
KEY_SLEFT シフトした左矢印キー
KEY_SMESSAGE Shifted message key
KEY_SMESSAGE シフトしたメッセージキー
KEY_SMOVE Shifted move key
KEY_SMOVE シフトした移動キー
KEY_SNEXT Shifted next key
KEY_SNEXT シフトしたネクストキー
KEY_SOPTIONS Shifted options key
KEY_SOPTIONS シフトしたオプションキー
KEY_SPREVIOUS Shifted prev key
KEY_SPREVIOUS シフトした前キー
KEY_SPRINT Shifted print key
KEY_SPRINT シフトしたプリントキー
KEY_SREDO Shifted redo key
KEY_SREDO シフトした再実行キー
KEY_SREPLACE Shifted replace key
KEY_SREPLACE シフトした置換キー
KEY_SRIGHT Shifted right arrow
KEY_SRIGHT シフトした右矢印
KEY_SRSUME Shifted resume key
KEY_SRSUME シフトしたリジュームキー
KEY_SSAVE Shifted save key
KEY_SSAVE シフトした保存キー
KEY_SSUSPEND Shifted suspend key
KEY_SSUSPEND シフトしたサスペンドキー
KEY_SUNDO Shifted undo key
KEY_SUNDO シフトしたアンドゥキー
KEY_SUSPEND Suspend key
KEY_SUSPEND サスペンドキー
KEY_UNDO Undo key
KEY_UNDO アンドゥキー
Keypad is arranged like this:
キーパッドはこのように配置されています。
+-----+------+-------+
| A1 | up | A3 |
+-----+------+-------+
|left | B2 | right |
+-----+------+-------+
| C1 | down | C3 |
+-----+------+-------+
A few of these predefined values do not correspond to a
real key:
これら定義ずみの値のうち、少数は実際のキーと対応 しません。
o KEY_RESIZE is returned when the SIGWINCH signal has
been detected (see curs_initscr(3x) and resizeterm(3x)).
This code is returned whether or not keypad has been
enabled.
o SIGWINCH シグナルが検出されると、 KEY_RESIZE を返しま
す。 curs_initscr(3x) と resizeterm(3x) を参照して
ください。
keypad が有効か無効かにかかわらず、このコードを返します。
o KEY_MOUSE is returned for mouse-events (see
curs_mouse(3x)). This code relies upon whether or not
keypad(3x) has been enabled, because (e.g., with xterm
mouse prototocol) ncurses must read escape sequences,
just like a function key.
o マウスイベントに対して KEY_MOUSE を返します。
(curs_mouse(3x) を参照してください。)
(例えば xterm のマウスプロトコルにより) ncurses は
ファンクションキーと同様にエスケープ・シーケンスを
読む必要があるので、このコードは keypad(3x) が有効かどうか
に依存します。
The has_key routine takes a key-code value from the above
list, and returns TRUE or FALSE according to whether the
current terminal type recognizes a key with that value.
has_key ルーチンは、上表のキーコードの値に対して、現在の
端末がその値のキーを認識するかどうかによって、 TRUE または
FALSE を返します。
The library also supports these extensions:
このライブラリは、次の拡張機能をサポートしています。
define_key
defines a key-code for a given string (see de-
fine_key(3x)).
与えられた文字列に対するキーコードを定義する
(define_key(3x) を参照)
key_defined
checks if there is a key-code defined for a given
string (see key_defined(3x)).
与えられた文字列に対するキーコードの有無を調べる
(key_defined(3x) を参照)
All routines return the integer ERR upon failure and an
integer value other than ERR (OK in the case of ungetch())
upon successful completion.
すべてのルーチンは、失敗すると整数 ERR を返します。
成功した場合には、 ERR 以外の整数値 (ungetch() の場合は
OK) を返します。
ungetch
returns ERR if there is no more room in the FIFO.
FIFO にそれ以上の余地がなければ、 ERR を返します。
wgetch
returns ERR if the window pointer is null, or if
its timeout expires without having any data.
ウィンドウポインタがヌルの場合、または何もデータが
ないままタイムアウトした場合に、 ERR を返します。
Functions with a "mv" prefix first perform a cursor move-
ment using wmove, and return an error if the position is
outside the window, or if the window pointer is null.
mv で始まる関数は、最初に wmove を使用してカーソルを移動
し、位置がウィンドウの外だった場合、またはウィンドウポインタ
がヌルの場合にエラーを返します。
Use of the escape key by a programmer for a single charac-
ter function is discouraged, as it will cause a delay of
up to one second while the keypad code looks for a follow-
ing function-key sequence.
エスケープキーを単一文字として使用しようとすると上手く行か
ない場合があります。 キーパッドのコードが後続のファンクション
キーシーケンスを待つ間、最高 1 秒に達する遅れが発生するためで
す。
Some keys may be the same as commonly used control keys,
e.g., KEY_ENTER versus control/M, KEY_BACKSPACE versus
control/H. Some curses implementations may differ accord-
ing to whether they treat these control keys specially
(and ignore the terminfo), or use the terminfo defini-
tions. Ncurses uses the terminfo definition. If it says
that KEY_ENTER is control/M, getch will return KEY_ENTER
when you press control/M.
いくつかのキーは、一般的な制御キーと等価である可能性がある
ことに注意してください。例えば、 KEY_ENTER とcontrol/M、
KEY_BACKSPACE とcontrol/H などです。
これらの制御キーを特別に扱う (そして terminfo を無視する)
かどうか、または terminfo の定義を使用するかどうかは、
curses の実装方法により異なる可能性があります。
ncurses は terminfo の定義を使用します。
terminfo で KEY_ENTER を control/M と書いていれば、
getch は control/M を押したときに KEY_ENTER を返します。
Generally, KEY_ENTER denotes the character(s) sent by the
Enter key on the numeric keypad:
一般的に、 KEY_ENTER はテンキーパッドの Enter キーから送
られる文字(列)を表します。
o the terminal description lists the most useful keys,
o 端末の記述は最も便利なキーをリストアップしており、
o the Enter key on the regular keyboard is already han-
dled by the standard ASCII characters for carriage-re-
turn and line-feed,
o 通常のキーボードにある Enter キーは復帰と改行の ASCII 文
字として扱われており、
o depending on whether nl or nonl was called, pressing
"Enter" on the regular keyboard may return either a
carriage-return or line-feed, and finally
o nl または nonl が呼び出されたかどうかにより、通常のキー
ボードにある "Enter" キーを押すと復帰または改行を返し、
o "Enter or send" is the standard description for this
key.
o 最終的に "入力または送信" がこのキーの標準の記述となりま
す。
When using getch, wgetch, mvgetch, or mvwgetch, nocbreak
mode (nocbreak) and echo mode (echo) should not be used at
the same time. Depending on the state of the tty driver
when each character is typed, the program may produce un-
desirable results.
getch、 wgetch、 mvgetch あるいは mvwgetch を使うとき、
nocbreak モード (nocbreak) と echo モード (echo) を同時に
使ってはいけません。各文字がタイプされた時の tty ドライバの
状態によっては、プログラムは望ましくない結果を出す可能性が
あります。
Note that getch, mvgetch, and mvwgetch may be macros.
getch, mvgetch および mvwgetch はマクロであるかもしれ
ないことに注意してください。
Historically, the set of keypad macros was largely defined
by the extremely function-key-rich keyboard of the AT&T
7300, aka 3B1, aka Safari 4. Modern personal computers
usually have only a small subset of these. IBM PC-style
consoles typically support little more than KEY_UP,
KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END,
KEY_NPAGE, KEY_PPAGE, and function keys 1 through 12. The
Ins key is usually mapped to KEY_IC.
歴史的に、キーパッドマクロの大半は、ファンクションキーの
非常に多い AT&T 7300、aka 3B1、aka Safari 4 のキーボードに
よって定義されてきました。 現代のパソコンは通常、これらの一
部分だけを持っています。 IBM PC と互換機は、せいぜい
KEY_UP、 KEY_DOWN、 KEY_LEFT、 KEY_RIGHT、 KEY_HOME、
KEY_END、 KEY_NPAGE、 KEY_PPAGE とファンクションキー 1 〜
12 をサポートする程度です。
Ins キーは通常、 KEY_IC にマップされます。
The *get* functions are described in the XSI Curses stan-
dard, Issue 4. They read single-byte characters only.
The standard specifies that they return ERR on failure,
but specifies no error conditions.
*get* 関数は XSI Curses standard, Issue 4 に記述されて
います。 これらは 1バイト文字だけを読み込みます。
XSI Curses standard では、それらが失敗すれば ERR を
返すことを明記していますが、エラーの条件は明記していません。
The echo behavior of these functions on input of KEY_ or
backspace characters was not specified in the SVr4 docu-
mentation. This description is adopted from the XSI Curs-
es standard.
KEY_ またはバックスペース文字の入力でのこれらの関数の
echo の動作は、 SVr4 文書では明記されていません。
この記述は XSI Curses standard から採用されました。
The behavior of getch and friends in the presence of han-
dled signals is unspecified in the SVr4 and XSI Curses
documentation. Under historical curses implementations,
it varied depending on whether the operating system's im-
plementation of handled signal receipt interrupts a
read(2) call in progress or not, and also (in some imple-
mentations) depending on whether an input timeout or non-
blocking mode has been set.
シグナル操作が存在する場合の getch 類の動作は、 SVr4
および XSI Curses 文書には定義されていません。過去の
curses の実装では、オペレーティングシステムのシグナル受取
り操作の実装が進行中の read(2) 呼び出しを中断させるかど
うかに依存して、そしてまた、(いくつかの実装で) 入力タイム
アウトまたは非ブロッキングモードが設定されているかどうか
に依存して異なりました。
KEY_MOUSE is mentioned in XSI Curses, along with a few re-
lated terminfo capabilities, but no higher-level functions
use the feature. The implementation in ncurses is an ex-
tension.
KEY_MOUSE は XSI Curses では関係のある若干個の terminfo
の機能についてのみ記載されていますが、その機能を用いる上
位レベルの関数については触れられていません。 ncurses での
実装は、拡張のひとつとなっています。
KEY_RESIZE is an extension first implemented for ncurses.
NetBSD curses later added this extension.
KEY_RESIZE は ncurses で初めて実装された拡張機能です。
後に NetBSD curses にも追加されました。
Programmers concerned about portability should be prepared
for either of two cases: (a) signal receipt does not in-
terrupt getch; (b) signal receipt interrupts getch and
causes it to return ERR with errno set to EINTR. Under
the ncurses implementation, handled signals never inter-
rupt getch.
移植性に関心のあるプログラマは、次の 2 つのケースの両方
に対して準備しなくてはなりません。
(a) シグナルの受け取りが getch に割り込まない場合。
(b) シグナルの受け取りが getch に割り込み、 errno に
EINTR をセットして ERR を返す場合。
ncurses の実装では、シグナル操作は決して getch に割り
込みません。
The has_key function is unique to ncurses. We recommend
that any code using it be conditionalized on the NCURS-
ES_VERSION feature macro.
has_key 関数は ncurses に特有です。これを使用するプログ
ラムはすべて NCURSES_VERSION マクロの条件付きとするよう
に勧めます。
curses(3x), curs_inopts(3x), curs_outopts(3x),
curs_mouse(3x), curs_move(3x), curs_refresh(3x),
resizeterm(3x).
Comparable functions in the wide-character (ncursesw) li-
brary are described in curs_get_wch(3x).
ワイド文字用ライブラリ (ncursesw) の対応する関数群は
curs_get_wch(3x) で説明しています。
curs_getch(3x)