Intercept keystrokes?
Is it possible to write a plugin that runs in the background and:
- listens for an arbitrary hot key
- enters into a temporary mode where subsequent keystrokes are interpreted and generate actions that normally require use of the palette.
- reverts to background after a carriage return?
My use cases are transcribing choral parts with frequent meter changes and writing instrumental exercises with frequent key signature changes. I'd like to be able, while entering notes to type, say, :m5/8\n
to change to the meter to 5/8 or :k4f\n
to change the key signature to 4 flats.
Comments
Just checking to see if the lack of responses means I need to rephrase the question for clarity. Thanks!
In reply to Just checking to see if the… by michael_ellis
my 2 cents
> runs in the background
asaik, no background listener MS3 except the onScoreStateChanged Handler
> key capture
QML Item{} and inherited can capture when user has focus (ie clicked on it)
event.accepted value to intercept or not
qml doc
plugin snippet
snippet of an alternative way to intercept (should avoid, coz of the bug)
> send keystroke
unfortunately i have no idea, hope someone could help you
QGuiApplication.sendEvent seems to work but may need C++.
> send command / action
try out nonapi cmd()
i don't really know how to code your project but this seems similar to your idea and may interest you (i don't know how that plugin work either)
https://musescore.org/en/project/command-palette-archived
Cheers
In reply to my 2 cents > runs in the… by msfp
@msfp
Hey, thanks! Worth way more than 2 cents, especially the links cmd() and to the command palette project. I may be able to use the latter as the basis for my project.
What I've got in mind is a simple one-line text input that works a little like the Vim command line, e.g.
- type a hot key, maybe a colon
:
to pop it up with focus- very minimal interpreter
- Carriage return
\n
to invoke the command and return focus to the score, or- Escape to cancel the command
Not sure if this is so obviously it wasn't stated, or if I just missed it, but - you can assign a shortcut to a plugin. So invoking the plugin by shortcut is the easy part.
In reply to Not sure if this is so… by Marc Sabatella
Thanks, Marc. I did know that. Can you tell me if the plugin API (or nonapi cmd function) in MU4 currently supports inserting key and time signatures? Those seem to be the only frequently entered items (for my use case) that aren't supported by the Note Entry shortcuts. In searching for examples I came across an issue in the repo for Key Signature insertion (https://github.com/musescore/MuseScore/pull/2429). Can't tell if it a fix was ever committed.
Also, unless I've missed something, it seems like there's no log console available yet in MU4. Is that the case and if so is there an estimate of when one might become available?
In reply to Thanks, Marc. I did know… by michael_ellis
Sorry, I'm not an expert on the API, hopefully someone else can assist with that.
Meanwhile, though, you might consider a different approach entirely, such as the one used by Notation Express - see https://www.notationcentral.com/product/notation-express-stream-deck-pr…. it's based on sending keystrokes to perform palette search, I believe.
In reply to Sorry, I'm not an expert on… by Marc Sabatella
> Sorry, I'm not an expert on the API, hopefully someone else can assist with that.
No problem. I've decided to punt entirely on plugin development until the API is stable in MU4.
For my own use, it seems like the best approach is to write a music21 SubConverter that parses Tbon notation and sends MusicXML to MuseScore.
See:
- https://web.mit.edu/music21/doc/usersGuide/usersGuide_54_extendingConve…
- https://github.com/Michael-F-Ellis/tbon