0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

20分でまとめる備忘録 robloxでテキストボックス選択時にキーボード入力を止める方法

Posted at

備忘録のきっかけ

テキストボックスから文字入力中、キーボードに割り当てられたジャンプ・ダッシュなどが反応して後ろでキャラクターが暴れる事象が発生するので、ボックスに入力中はこれを黙らせる方法を探した

実装例

local function onInputBegan(input, _gameProcessed)
	if UserInputService:GetFocusedTextBox() == nil and input.UserInputType == Enum.UserInputType.Keyboard then
        print("sample")
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

If no TextBox is selected, this function will return nil.

テキストボックスを選択していない場合、GetFocusedTextBox()はboolでなくnilを返すのでnilチェックするので気を付ける。
設計的には入力中のテキストボックスが取れた方が、ここから入力文字列を取れるので便利そう。今回は選択中かが分かれば良いだけだったので関係はないが、今後使う可能性はありそう

おわりに

入力系はこの時は受け付けたい・この場合は受け付けたくないケースが複雑になりがち。しっかり切り分ける仕組みを用意するのが肝心そう

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?