Last active
January 6, 2025 23:05
-
-
Save dagronf/51a1ccf92f528ffab7183e3bdc457ac4 to your computer and use it in GitHub Desktop.
[macOS] Swift wrapper for virtual keycodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Carbon | |
public struct KeyCode { | |
// * Discussion: | |
// * These constants are the virtual keycodes defined originally in | |
// * Inside Mac Volume V, pg. V-191. They identify physical keys on a | |
// * keyboard. Those constants with "ANSI" in the name are labeled | |
// * according to the key position on an ANSI-standard US keyboard. | |
// * For example, kVK_ANSI_A indicates the virtual keycode for the key | |
// * with the letter 'A' in the US keyboard layout. Other keyboard | |
// * layouts may have the 'A' key label on a different physical key; | |
// * in this case, pressing 'A' will generate a different virtual | |
// * keycode. | |
// */ | |
public static let A: Int = kVK_ANSI_A | |
public static let S: Int = kVK_ANSI_S | |
public static let D: Int = kVK_ANSI_D | |
public static let F: Int = kVK_ANSI_F | |
public static let H: Int = kVK_ANSI_H | |
public static let G: Int = kVK_ANSI_G | |
public static let Z: Int = kVK_ANSI_Z | |
public static let X: Int = kVK_ANSI_X | |
public static let C: Int = kVK_ANSI_C | |
public static let V: Int = kVK_ANSI_V | |
public static let B: Int = kVK_ANSI_B | |
public static let Q: Int = kVK_ANSI_Q | |
public static let W: Int = kVK_ANSI_W | |
public static let E: Int = kVK_ANSI_E | |
public static let R: Int = kVK_ANSI_R | |
public static let Y: Int = kVK_ANSI_Y | |
public static let T: Int = kVK_ANSI_T | |
public static let _1: Int = kVK_ANSI_1 | |
public static let _2: Int = kVK_ANSI_2 | |
public static let _3: Int = kVK_ANSI_3 | |
public static let _4: Int = kVK_ANSI_4 | |
public static let _6: Int = kVK_ANSI_6 | |
public static let _5: Int = kVK_ANSI_5 | |
public static let equal: Int = kVK_ANSI_Equal | |
public static let _9: Int = kVK_ANSI_9 | |
public static let _7: Int = kVK_ANSI_7 | |
public static let minus: Int = kVK_ANSI_Minus | |
public static let _8: Int = kVK_ANSI_8 | |
public static let _0: Int = kVK_ANSI_0 | |
public static let rightBracket: Int = kVK_ANSI_RightBracket | |
public static let O: Int = kVK_ANSI_O | |
public static let U: Int = kVK_ANSI_U | |
public static let leftBracket: Int = kVK_ANSI_LeftBracket | |
public static let I: Int = kVK_ANSI_I | |
public static let P: Int = kVK_ANSI_P | |
public static let L: Int = kVK_ANSI_L | |
public static let J: Int = kVK_ANSI_J | |
public static let quote: Int = kVK_ANSI_Quote | |
public static let K: Int = kVK_ANSI_K | |
public static let semicolon: Int = kVK_ANSI_Semicolon | |
public static let backslash: Int = kVK_ANSI_Backslash | |
public static let comma: Int = kVK_ANSI_Comma | |
public static let slash: Int = kVK_ANSI_Slash | |
public static let N: Int = kVK_ANSI_N | |
public static let M: Int = kVK_ANSI_M | |
public static let period: Int = kVK_ANSI_Period | |
public static let grave: Int = kVK_ANSI_Grave | |
public static let keypadDecimal: Int = kVK_ANSI_KeypadDecimal | |
public static let keypadMultiply: Int = kVK_ANSI_KeypadMultiply | |
public static let keypadPlus: Int = kVK_ANSI_KeypadPlus | |
public static let keypadClear: Int = kVK_ANSI_KeypadClear | |
public static let keypadDivide: Int = kVK_ANSI_KeypadDivide | |
public static let keypadEnter: Int = kVK_ANSI_KeypadEnter | |
public static let keypadMimus: Int = kVK_ANSI_KeypadMinus | |
public static let keypadEquals: Int = kVK_ANSI_KeypadEquals | |
public static let keypad0: Int = kVK_ANSI_Keypad0 | |
public static let keypad1: Int = kVK_ANSI_Keypad1 | |
public static let keypad2: Int = kVK_ANSI_Keypad2 | |
public static let keypad3: Int = kVK_ANSI_Keypad3 | |
public static let keypad4: Int = kVK_ANSI_Keypad4 | |
public static let keypad5: Int = kVK_ANSI_Keypad5 | |
public static let keypad6: Int = kVK_ANSI_Keypad6 | |
public static let keypad7: Int = kVK_ANSI_Keypad7 | |
public static let keypad8: Int = kVK_ANSI_Keypad8 | |
public static let keypad9: Int = kVK_ANSI_Keypad9 | |
/* keycodes for keys that are independent of keyboard layout */ | |
public static let `return`: Int = kVK_Return | |
public static let tab: Int = kVK_Tab | |
public static let space: Int = kVK_Space | |
public static let delete: Int = kVK_Delete | |
public static let escape: Int = kVK_Escape | |
public static let command: Int = kVK_Command | |
public static let shift: Int = kVK_Shift | |
public static let capslock: Int = kVK_CapsLock | |
public static let option: Int = kVK_Option | |
public static let control: Int = kVK_Control | |
public static let rightCommand: Int = kVK_RightCommand | |
public static let rightShift: Int = kVK_RightShift | |
public static let rightOption: Int = kVK_RightOption | |
public static let rightControl: Int = kVK_RightControl | |
public static let fn: Int = kVK_Function | |
public static let f17: Int = kVK_F17 | |
public static let volumeUp: Int = kVK_VolumeUp | |
public static let volumeDown: Int = kVK_VolumeDown | |
public static let mute: Int = kVK_Mute | |
public static let f18: Int = kVK_F18 | |
public static let f19: Int = kVK_F19 | |
public static let f20: Int = kVK_F20 | |
public static let f5: Int = kVK_F5 | |
public static let f6: Int = kVK_F6 | |
public static let f7: Int = kVK_F7 | |
public static let f3: Int = kVK_F3 | |
public static let f8: Int = kVK_F8 | |
public static let f9: Int = kVK_F9 | |
public static let f11: Int = kVK_F11 | |
public static let f13: Int = kVK_F13 | |
public static let f16: Int = kVK_F16 | |
public static let f14: Int = kVK_F14 | |
public static let f10: Int = kVK_F10 | |
public static let f12: Int = kVK_F12 | |
public static let f15: Int = kVK_F15 | |
public static let help: Int = kVK_Help | |
public static let home: Int = kVK_Home | |
public static let pageUp: Int = kVK_PageUp | |
public static let forwardDelete: Int = kVK_ForwardDelete | |
public static let f4: Int = kVK_F4 | |
public static let `end`: Int = kVK_End | |
public static let f2: Int = kVK_F2 | |
public static let pageDown: Int = kVK_PageDown | |
public static let f1: Int = kVK_F1 | |
public static let leftArrow: Int = kVK_LeftArrow | |
public static let rightArrow: Int = kVK_RightArrow | |
public static let downArrow: Int = kVK_DownArrow | |
public static let upArrow: Int = kVK_UpArrow | |
/* ISO keyboards only*/ | |
public static let isoSection: Int = kVK_ISO_Section | |
/* JIS keyboards only*/ | |
public static let jis_yen: Int = kVK_JIS_Yen | |
public static let jis_underscore: Int = kVK_JIS_Underscore | |
public static let jis_keypadComma: Int = kVK_JIS_KeypadComma | |
public static let jis_eisu: Int = kVK_JIS_Eisu | |
public static let jis_kana: Int = kVK_JIS_Kana | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment