nour
nour

Reputation: 3

how to call function key (F1, F2, F3) in Swift?

I'm trying to add a button in an IOS app using Swift so that when it's clicked, it executes F1...F12 in a regular keyboard for a Mac or Windows. I look into UIKeyCommand but that doesn't solve the problem.

Upvotes: 0

Views: 373

Answers (1)

BrainPumpkin
BrainPumpkin

Reputation: 3

the KeyCodes of the F1, F2 is 0x7A and 0x78. For f3 I did not find

let keyDown = CGEvent(keyboardEventSource: nil, virtualKey: 0x7A, keyDown: true)
let keyUp = CGEvent(keyboardEventSource: nil, virtualKey: 0x7A, keyDown: false)
    
keyDown?.post(tap: .cghidEventTap)
keyUp?.post(tap: .cghidEventTap)

the same for f2

Upvotes: 0

Related Questions