ダイアログマネージャーが自身を閉じる方法のカスタマイズ:ESCキーの検出、2回目(失敗)の試み
本文の状態
日本語全文を表示中
詳細モードで約2分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Andrej Karpathy 厳選
ダイアログマネージャーがESCキーで閉じる方法をカスタマイズする2回目の試みが失敗。同期キーボード状態の検出はまだ不正確。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
前回、GetAsyncKeyState関数について見ました。
この関数は、イベント発生時にESCキーが押されていたかどうかを教えてくれるという点では役立ちますが、ESCキーが押されていたからといって、そのメッセージを受け取った理由がESCキーであるとは限りません。
例えば、あなたの方針が単にESCキーを無視し、ユーザーが閉じるボタンをクリックした場合にのみダイアログを閉じるものだとします。ユーザーがESCキーを押し続けながら閉じるボタンをクリックした場合、ESCキーの最初の押下がIDCANCEL通知を生成します。
そして、次のIDCANCEL通知は、閉じるボタンによって生成されます。
ただし、これはESCキーから来たものではありません。閉じるボタンから来たのです。たまたまESCキーが押されていただけで、二つ目のIDCANCEL通知を受け取った理由はそれではないのです。
二つの入口、裏口と正面入口がある部屋にキオスクを設置していると想像してください。誰かが正面ドアから入ってきたら受付係を呼び出したいのですが、裏口から入ってきた場合はそうしたくありません。ESCキーをチェックすることで私たちがやっていることは、「もし裏口が開いていたら、受付係を呼び出さない」と言っているようなものです。しかし、誰かがちょうど裏口の戸口に立ち、ドアを開けたままにしている間に、別の誰かが正面ドアから入ってくる可能性があります。あなたのロジックは裏口が開いていることを検知し、一度に開いているドアは一つだけだと想定していたため、受付係への呼び出しを抑制してしまいます。
次回は、ESCキーと閉じるボタンの区別について見ていきます。
原文を表示
Last time, we saw that GetAsyncKeyState
It helps, in that it tells you whether the ESC key was down when the event occurred, but just because the ESC is down doesn’t mean that the ESC key is why you got the message.
For example, suppose your policy is to simply ignore the ESC key, but to close the dialog if the user clicks the Close button. If the user holds the ESC key and clicks the Close button, the initial press of the ESC will generate an IDCANCEL
And then the next IDCANCEL
Except that it didn’t come from the ESC key. It came from the Close button. It just so happens that the ESC is down, but that’s not the reason why you got the second IDCANCEL
Suppose you have a kiosk in a room with two entrances, a back entrance and a front entrance. If someone enters from the front door, you want to call the receptionist, but you don’t want to do it if they enter from the back door. What we’re doing by checking the ESC key is saying, “If the back door is open, then don’t call the receptionist.” But it’s possible that somebody is just standing in the back doorway, holding the door open, and during that time, somebody comes in the front door. Your logic sees that the back door is open and suppresses the call to the receptionist because you had assumed that only one door can be open at a time.
Next time, we’ll look at distinguishing ESC from Close.
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み