implement async keyboard event sending
This commit is contained in:
1 parent
c8262da5d7
commit
7e8be94530
1 file changed
+23
-8
@@ -195,7 +195,7 @@ import UIKit
|
|||||||
let previouslySelectedIndexPath = tableView.indexPathForSelectedRow
|
let previouslySelectedIndexPath = tableView.indexPathForSelectedRow
|
||||||
tableView.layoutIfNeeded()
|
tableView.layoutIfNeeded()
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
|
|
||||||
if let indexPath = previouslySelectedIndexPath {
|
if let indexPath = previouslySelectedIndexPath {
|
||||||
// Make sure the indexPath is still valid and scroll to the selected indexPath
|
// Make sure the indexPath is still valid and scroll to the selected indexPath
|
||||||
if indexPath.row < tableView.numberOfRows(inSection: indexPath.section) {
|
if indexPath.row < tableView.numberOfRows(inSection: indexPath.section) {
|
||||||
@@ -255,14 +255,29 @@ import UIKit
|
|||||||
print("Sending key-value")
|
print("Sending key-value")
|
||||||
|
|
||||||
let keyboardCmdStrings = CommandManager.shared.extractKeyStrings(from: cmd.keyboardCmdString)
|
let keyboardCmdStrings = CommandManager.shared.extractKeyStrings(from: cmd.keyboardCmdString)
|
||||||
for keyStr in keyboardCmdStrings! {
|
sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings!)
|
||||||
LiSendKeyboardEvent(CommandManager.keyMappings[keyStr]!,Int8(KEY_ACTION_DOWN), 0)
|
}
|
||||||
print("keycode: \(CommandManager.keyMappings[keyStr] ?? 0xFF)")
|
|
||||||
Thread.sleep(forTimeInterval: 0.05)
|
private func sendKeyDownEventWithDelay(keyboardCmdStrings: [String], delay: TimeInterval = 0.05, index: Int = 0) {
|
||||||
|
guard index < keyboardCmdStrings.count else {
|
||||||
|
for keyStr in keyboardCmdStrings {
|
||||||
|
LiSendKeyboardEvent(CommandManager.keyMappings[keyStr]!,Int8(KEY_ACTION_UP), 0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
} // 如果已经处理完所有键,释放所有按键
|
||||||
|
|
||||||
|
let keyCode = CommandManager.keyMappings[keyboardCmdStrings[index]]
|
||||||
|
guard let keyCode = keyCode else {
|
||||||
|
print("No mapping found for \(keyboardCmdStrings[index])")
|
||||||
|
sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个
|
||||||
|
return
|
||||||
}
|
}
|
||||||
for keyStr in keyboardCmdStrings! {
|
// 发送当前键的键盘按下事件
|
||||||
LiSendKeyboardEvent(CommandManager.keyMappings[keyStr]!,Int8(KEY_ACTION_UP), 0)
|
LiSendKeyboardEvent(keyCode,Int8(KEY_ACTION_DOWN), 0)
|
||||||
|
// 使用 asyncAfter 在指定延迟后发送下一个键的键盘按下事件
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
|
||||||
|
self.sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user