BasicsTutorial/More on keyboard input

Last-modified: 2009-11-29 (日) 22:16:05

More on keyboard input

キーボード入力に関してより多くの

You already know these five commands for keyboard input.
あなたは、キーボード入力のためにすでにこれらの5つの命令を知っている。

Spacekey() = space bar
Spacekey()=スペース・バー
Controlkey() = control
Controlkey()=コントロール
Returnkey() = return
Returnkey()=RETURN
Shiftkey() = shift
Shiftkey()=シフト
Escapekey() = escape
Escapekey()=エスケープ

If you can’t remember, they all return 1 when called if the button is pressed.
あなたが覚えていることができないならば、ボタンが押されたとき、それ全部は1を返す。
If not they return 0.
もしそうでなければ、それは0を返す。

But that’s not any good if you want to have full control over the keyboard.
しかし、あなたがキーボードの上に完全なコントロールがありたいならば、それは少しも役に立たない。

We’ll start with the INKEY$() command.
我々は、INKEY$()命令から始める。

INKEY$()

Do
  `Store the string of the key pressed
  ` 押したキーの文字を格納する
  keyPressed$ = inkey$()
  `If a key was pressed say which one
  ` キーが押されたか否か
  If keyPressed$ <> ""
     If keyHold = 0
        Print "You pressed ", keyPressed$
        keyHold = 1
     Endif
  Else
     `Otherwise clear the screen
     ` なもなければ画面を消去する
     Cls
     keyHold = 0
  Endif
Loop

The INKEY$() command first of all returns a string, not an integer or float.
INKEY$()命令はまず第一に、文字を返す、整数またはフロートでない。
That is why it has $ on the end of it.
そういうわけで、それは変数名の終わりの上に、$を持つ。
This is not the case for commands that return floats, all commands that return numbers have no symbol.
これが、戻り値がフロート命令のために、本当であるというわけではない。(戻り値がシンボルを持たないという全ての命令)

The string that the INKEY$() command returns is the string of the key, or key combination that has been pressed.
そのINKEY$()命令が、文字キーの文字列または押されたキーの組み合わせであることを答える。
So if the A key has been pressed, the string “a” (lower case) is returned, however if Shift and A are pressed together “A” (upper case) is returned.
もし、Aキーが押されたときに、文字「a」(小文字)返す、しかし、シフトとAが一緒に押されるならば、「A」(大文字の)は返される。
This is a quick and easy way of getting the key you want.
これは、あなたが望むキーを得る迅速かつ容易な方法である。
I also put in the variable ‘keyHold’ that helps in only printing once and not constantly printing.
私は同様に、変数「 keyHold 」が ただ1度印刷するだけであって、そして絶えず印刷しないことにおいて、助ける。
I’m sure you can figure out how, just go through the code in your mind, line by line thinking what the value of ‘keyHold’ is.
私はあなたが方法を見つけ出すことができると確信する、ちょっと、一行一行『keyHold』の値が何であるかについて考えて、あなたの心でコードを調べなさい。

The only problem with the INKEY$() command is that it only returns strings, and keys like Return, Shift and Alt don’t return strings (I know there are other commands for some of these buttons, but then we’d need to call more than one command to find if those keys are pressed).
INKEY$()命令で唯一の問題はそれが文字列とRETURNのようなキーを返すだけであるということである、戻る文字がシフトとアルトはそうしない(私は他の命令がこれらのボタンのいくつかのためにあるということを知っている、だが、我々はそれらのキーが押されるならば、見つける複数の命令を呼ぶ必要があるだろう)。
All of the buttons on the keyboard have a unique code (the buttons themselves, not the characters, so SHIFT A will return the same value as A on its own).
キーボードのボタンの全てには、ユニークなコード((キャラクタでない)ボタンは、それ自身、同じものは単独でAとして評価する)がある。
This code is found by the command SCANCODE().
このコードは、命令SCANCODE()によって見つかる。

SCANCODE()

Do
  Print scancode()
Loop

Here is a diagram of all the scan codes.
全てのスキャーンコードの図は、ここにある。

KEYSTATE()

If you just want to check for one key being pressed you can alternatively use KEYSTATE().
もし、あなたがちょうど押されている1つのキーについて調べたいならば、あなたがKEYSTATE()を代わりに使うことができる。
KEYSTATE() uses the scan code for the keys in order to check if they are pressed.
KEYSTATE()、それが押されるならば、チェックするために、キーのためにスキャーンコードを使用する。
It returns a 1 when the specified key is pressed.
指定されたキーが押されるとき、それは1を返す。

Do
  If keystate(57) = 1 then print “Space is pressed”
  If keystate(58) = 1 then print “Caps Lock is pressed”
  If keystate(201) = 1 then print “Page Up is pressed”
  If keystate(30) = 1 then print “A is pressed”
Loop

KEYSTATE is around 4 times faster as all the keys don’t have to be checked.
全てのキーがチェックされる必要があるというわけではなくて、KEYSTATEはおよそ4回より速い。
Also KEYSTATE allows you to detect if more than one key is being pressed.
また、KEYSTATEは複数のキーが押されているかどうかを検出することができる。
Try pressing all the keys at once (and your PC’ll probably make that horrible bleeping sound :D).
すぐに全てのキーを押して試みなさい(そして、あなたのPC'llは、多分その恐ろしい電子音を発している物音をたてるだろう:D)。

If you want to access the arrow_keys fast you can use these commands, exactly like SPACEKEY() and the other similar commands.
もしあなたが速く arrow_keys にアクセスすることを望むなら、あなたは正確に SPACEKEY () と他の類似のコマンドのように、これらのコマンドを使うことができる。

特殊なキー

Upkey() = up arrow
Upkey()=上向の矢
Rightkey() = right arrow
Rightkey()=左の矢
Downkey() = down arrow
Downkey()=下向きの矢
Leftkey() = left arrow
Leftkey()=左の矢

They all return 1 if the relevant key is pressed.
関連したキーが押されるならば、それ全部は1を返す。

However, what if you want something like typing, where you need every key pressed by the user between the last loop and this loop?
しかし、あなたがあなたが最後のループと このループの間でユーザーが押しているあらゆるキーを必要とするタイピングのような何かを望むならば、どうですか?
The user may have pressed more than one key between the last check for keys and this check if the loop is slow because lots is happening.
たくさんが起こっているのでループが遅いならば、ユーザーはキーとこのチェックの最後のチェックの間で複数のキーを押したかもしれない。
The INKEY$() and SCANCODE() commands only record the keys that are pressed at the time of checking.
INKEY$()、そして、SCANCODE()命令はチェックする時点での押されるキーを記録するだけである。
This is when you use the keyboard buffer.
これは、あなたがキーボード・バッファを使う時である。

keyboard buffer

do
  `If there is something in the keyboard buffer
  `もし、キーバッファに何かが入っているならば
  if entry$()<>""
     `Print it
     print entry$();
     `Clear the buffer
     clear entry buffer
  endif
  `If return is pressed, go to a new line
  ` もしreturnキーが押されるなら、新しい行に行く
  if returnkey()=1
     if keyHold=0
        print
        keyHold=1
     endif
  else
     keyHold=0
  endif
loop

This code will print any strings that it finds in the keyboard buffer on the screen, and go to a new line when the return key is pressed.
リターンキーが押されるとき、このコードはそれがスクリーンでキーボード・バッファで見つけるどんな文字でもプリントして、新しい行に行く。

ENTRY$() returns the contents of the keyboard buffer as a string.
ENTRY$()は、文字としてキーボード・バッファの内容を返す。
Any characters typed are stored in the keyboard buffer.
タイプされるどんなキャラクタでも、キーボード・バッファに保存される。
In our code, we check if ENTRY$()<>””, i.e. if there is something in the entry buffer, and if there is we print it and use CLEAR ENTRY BUFFER to delete the string stored in the buffer.
我々のコードでは、ENTRY$()<>”” ならば、我々が確認して、すなわち、何かがエントリーバッファにあるならば、そして、我々がいるならば、それをプリントして、バッファに格納される文字列を削除するために CLEAR ENTRY BUFFERを使いなさい。
Otherwise we will keep reading the same, ever increasing string again and again and again.
さもなければ、我々は何度も何度も同じ、これまでに増加している文字列を読み続ける。
We also use the ‘keyHold’ method again for preventing the holding of the return key.
我々も、再びリターンキーの保持を防ぐ『keyHold』方法を使用する。

Summary of Commands

命令の概要

· IINKEY$() - Returns the string of the key that is pressed, returns a “” if no key is pressed.
INKEY$()- 押されるキーの文字列を返して、キーが押されないならば“”を返す。ヌル

· SCANCODE() - Returns the scan code of the key that is pressed.
SCANCODE()- 押されるキーのスキャーンコードを返す。
Each key has its own unique scan code.
各々のキーには、それ自身のユニークなスキャーンコードがある。
Returns 0 if no key is pressed.
キーが押されないならば、0を返す。

· KEYSTATE(scancode) - Returns a 1 if the key with the specified scan code is pressed, returns 0 if not.
KEYSTATE(scancode) - 指定されたスキャーンコードによるキーが押されて、もしそうでなければ0を返す、ならば1が答える。
This is useful for finding if more than 1 key is pressed.
1つ以上のキーが押されるならば、これは発見に役立つ。

· UPKEY(), RIGHTKEY(), DOWNKEY(), LEFTKEY() - Returns a 1 if the relevant arrow key is pressed, returns 0 if not.
UPKEY()、RIGHTKEY()、DOWNKEY()、LEFTKEY()- 帰る1関連した矢印キーが押されるなら1を返す。(もしそうでなければ0を返す)。

· ENTRY$() - Returns the string stored in the keyboard buffer.
ENTRY$()- 文字がキーボード・バッファに保存したものを返す。
When a key is pressed windows adds its string to the buffer.
キーが押されたウインドウである時は、その文字をバッファに加える。
Use CLEAR ENTRY BUFFER to delete the contents of the string.
文字列の内容を削除するために、CLEAR ENTRY BUFFERを使いなさい。

· CLEAR ENTRY BUFFER - Clears the contents of the keyboard buffer.
CLEAR ENTRY BUFFER - キーボード・バッファの中身を削除する。

End of Section Tasks

セクション終わりの作業

l Make a program that types the keys you press and changes colour when you press different function keys.
あなたが異なるファンクションキーを押すとき、あなたが押す、そして、変化が色づけるキーを入力するプログラムを行いなさい。