Skip to content

Commit

Permalink
feat: add option to output mouse position commands with predefined du…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
socsieng committed Jun 18, 2021
1 parent bd80c6e commit f662869
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/SendKeysLib/MouseEventProcessor.swift
Expand Up @@ -28,12 +28,12 @@ struct RawMouseEvent {
}
}

struct MouseEvent: CustomStringConvertible {
class MouseEvent: CustomStringConvertible {
let eventType: MouseEventType
let button: MouseButton
let startPoint: CGPoint
let endPoint: CGPoint
let duration: TimeInterval
var duration: TimeInterval

static let numberFormatter = createNumberFormatter()

Expand Down
13 changes: 13 additions & 0 deletions Sources/SendKeysLib/MousePosition.swift
Expand Up @@ -19,6 +19,13 @@ class MousePosition: ParsableCommand {
help: "Displays results as either a series of coordinates or commands.")
var mode = OutputMode.coordinates

@Option(
name: .shortAndLong,
help:
"Duration (in seconds) to output for mouse events. A negative value uses elapsed time between mouse events."
)
var duration: Double = -1

static let eventProcessor = MouseEventProcessor()

required init() {
Expand Down Expand Up @@ -93,6 +100,12 @@ class MousePosition: ParsableCommand {
let command: MousePosition = bridge(ptr: UnsafeRawPointer(refcon)!)

if let mouseEvent = MousePosition.eventProcessor.consumeEvent(type: eventType, event: event) {

// if duration is set, override all mouse event durations
if command.duration >= 0 {
mouseEvent.duration = command.duration
}

switch command.mode {
case .coordinates:
if mouseEvent.eventType == .click {
Expand Down

0 comments on commit f662869

Please sign in to comment.