forked from raycast/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New Extension] Media Key Emulate (raycast#7394)
* global-media-key: init * tweak: resolved problem * build: update deps * Fix typo --------- Co-authored-by: Milena Araujo <mil3na@users.noreply.github.com>
- Loading branch information
Showing
25 changed files
with
2,062 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"root": true, | ||
"extends": ["@raycast"] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# misc | ||
.DS_Store | ||
|
||
# swiftc | ||
.build | ||
|
||
# https://developers.raycast.com/migration/v1.50.0 | ||
raycast-env.d.ts |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"printWidth": 120, | ||
"singleQuote": false | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Media Key Emulate Changelog | ||
|
||
## [Initial Version] - 2023-03-20 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Tiou Lims | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// swift-tools-version: 5.6 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "media-key", | ||
platforms: [ | ||
.macOS(.v10_15), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "media-key", | ||
dependencies: [] | ||
), | ||
] | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Media Key Emulate | ||
|
||
Emulate keyboard media keys press, reassign hotkey for media keys. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Quartz | ||
import Cocoa | ||
import Carbon | ||
import ApplicationServices | ||
|
||
|
||
func isProcessTrusted() -> Bool { | ||
let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: false] | ||
return AXIsProcessTrustedWithOptions(options as CFDictionary?) | ||
} | ||
|
||
// https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-34.12/IOHIDSystem/IOKit/hidsystem/ev_keymap.h.auto.html | ||
let dict = [ | ||
"sound_up": NX_KEYTYPE_SOUND_UP, | ||
"sound_down": NX_KEYTYPE_SOUND_DOWN, | ||
"play": NX_KEYTYPE_PLAY, | ||
"next": NX_KEYTYPE_NEXT, | ||
"previous": NX_KEYTYPE_PREVIOUS, | ||
"fast": NX_KEYTYPE_FAST, | ||
"rewind": NX_KEYTYPE_REWIND, | ||
] | ||
|
||
// help from https://stackoverflow.com/a/55854051 | ||
func HIDPostAuxKey(key: Int32) { | ||
func doKey(down: Bool) { | ||
let flags = NSEvent.ModifierFlags(rawValue: (down ? 0xa00 : 0xb00)) | ||
let data1 = Int((key<<16) | (down ? 0xa00 : 0xb00)) | ||
|
||
let ev = NSEvent.otherEvent(with: NSEvent.EventType.systemDefined, | ||
location: NSPoint(x:0,y:0), | ||
modifierFlags: flags, | ||
timestamp: 0, | ||
windowNumber: 0, | ||
context: nil, | ||
subtype: 8, | ||
data1: data1, | ||
data2: -1 | ||
) | ||
let cev = ev?.cgEvent | ||
cev?.post(tap: CGEventTapLocation.cghidEventTap) | ||
|
||
} | ||
doKey(down: true) | ||
// https://stackoverflow.com/a/75084671 | ||
usleep(useconds_t(1 * 1_000)) //will sleep for 1 millisecond (.001 seconds | ||
doKey(down: false) | ||
} | ||
|
||
let args = CommandLine.arguments | ||
let keyType = args[args.count - 1] | ||
if let raw = dict[keyType]{ | ||
print("Trusted: \(AXIsProcessTrusted())") | ||
if isProcessTrusted() { | ||
HIDPostAuxKey(key:raw) | ||
} else { | ||
print("This process is not authorized for assistive access") | ||
exit(1) | ||
} | ||
|
||
}else{ | ||
exit(1) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.