Skip to content

Instantly share code, notes, and snippets.

@chipjarred
chipjarred / CGKeyCode_Extension.swift
Last active February 19, 2024 02:59
Querying macOS if a key is pressed
import CoreGraphics
extension CGKeyCode
{
/*
* From Events.h in Carbon.framework
* Summary:
* Virtual keycodes
*
* Discussion:
@chipjarred
chipjarred / SwiftUIKeyDetection.swift
Last active June 2, 2023 18:52
Detecting keyboard state in SwiftUI
import SwiftUI
extension CGKeyCode
{
// Define whatever key codes you want to detect here
static let kVK_Space: CGKeyCode = 0x31
var isPressed: Bool {
CGEventSource.keyState(.combinedSessionState, key: self)
}