# **QML 鍵盤事件** 在開發製作應用程式上,QML在設計業面上也提供相當豐富的按鍵觸發提供給開發者做編寫。 在做事件的程式撰寫前,必須在MouseArea區域先作一些設置。 ``` MouseArea{ focus: true // 聚焦該Scope Keys.enabled: true // 按鍵開啟 Keys.onPressed: { ... } } ``` 當然這裡也不單單就單一個事件註冊,剩下幾十個按鈕就讓開發者自己探索。 以下表格作為介紹: ### **全部共用** | QML註冊方式 | 補充 | | -------- | -------- | | Keys.onPressed | 按鍵被按下時 | | Keys.onReleased | 按鍵彈起來時 | | Keys.onShortcutOverride | 快速點擊 | ### **數字鍵** | 鍵盤按鍵 | QML註冊方式 | 補充 | | -------- | -------- | -------- | | 0 | Keys.onDigit0Pressed | 主鍵盤(英文輸入法)與數字鍵盤中同時 | | 1 | Keys.onDigit1Pressed | 同上 | | 2 | Keys.onDigit2Pressed | 同上 | | 3 | Keys.onDigit3Pressed | 同上 | | 4 | Keys.onDigit4Pressed | 同上 | | 5 | Keys.onDigit5Pressed | 同上 | | 6 | Keys.onDigit6Pressed | 同上 | | 7 | Keys.onDigit7Pressed | 同上 | | 8 | Keys.onDigit8Pressed | 同上 | | 9 | Keys.onDigit9Pressed | 同上 | | 0-9 | Keys.onNumberSignPressed | 數字鍵觸發時候 | | * | Keys.asteriskPressed | | ### **控制鍵** | 鍵盤按鍵 | QML註冊方式 | 補充 | | -------- | -------- | -------- | | ↑ | Keys.onHangupPressed | 方向鍵 | | → | Keys.onRightPressed || | ↑ | Keys.onDownPressed || | ← | Keys.onLeftPressed || | Delete | Keys.onDeletePressed | | ### **主按鍵 及 功能鍵** | 鍵盤按鍵 | QML註冊方式 | 補充 | | -------- | -------- | -------- | | esc | Keys.onEscapePressed | | | Tab | Keys.onTabPressed || | Space | Keys.onSpacePressed | 空白鍵 | | Tab + Space | Keys.onBacktabPressed | Tab和Space雙鍵一起按下 | | back | Keys.onBackPressed | 迴車鍵 | | Enter | Keys.onEnterPressed | 鍵盤區的enter相同 | | 🔉 | Keys.onVolumeDownPressed | 音量下降 | | 🔊 | Keys.onVolumeUpPressed | 音量提高 | <br><br> 參考資料: <br>https://doc.qt.io/qt-6/qml-qtquick-keys.html <br>https://blog.csdn.net/gongjianbo1992/article/details/116954979
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up