Checking if control/command key is currently pressed in VS Extensions - visual-studio-code

In my extension, I would like to check in a certain function, if the control (or command) key is currently pressed. How is that possible? I couldn't find any field that exposes this information.

If you read the below article
https://code.visualstudio.com/docs/extensionAPI/patterns-and-principles
It says
Visual Studio Code has a very rich extensibility model and there are many ways to extend the tool. However, we do not provide direct access to the underlying UI DOM to extension writers. With VS Code, we’re continually trying to optimize use of the underlying web technologies to deliver an always available, highly responsive editor and we will continue to tune our use of the DOM as these technologies and our product evolve. To maintain performance and compatibility, we run extensions in their own host process and prevent direct access to the DOM. VS Code also includes a built-in set of UI components for common scenarios such as IntelliSense, so that these experiences are consistent across programming languages and extensions and extension developers do not need to build their own.
We realize that this approach may initially feel restrictive to extension developers. We’re always looking for ways to improve our extensibility model and expand the capabilities available to extensions. We look forward to hearing your feedback and ideas.
This means your extension code doesn't run the in editor window context at all. And you can't hack into the webview as the extension api doesn't provide it. So you need to open a Feature request with VScode team and ask them to expose either the last keyboard event or atleast the status of Shift, Ctrl and alt keys. Currently they just discard it and throw it away (if no editor is open) else they send it to the monaco editor before checking for any shortcut combination

This does not directly answer your question but maybe helps solving your problem:
Your extension could contribute two different commands: For example first command myextension.runTarget (noDebug=true) and myextension.debugTarget (noDebug=false). In addition your extension can contribute keybindings that bind those two commands to different hotkeys, for instance CTRL + F5 and only F5.
Looks like vscode itself does it the same way (screenshot of keybindings view):

This question might be of use. With this approach you could track a key down event and then if the key code is equal to command (91 or 93 on Safari/Chrome, 224 on Firefox) or control. From there, you could put in your functionality if this returns as true, or however you want to structure it

Related

Where can I find possible rules for vscode key bindings?

I've googled for this (perhaps poorly?) and I can only seem to find list of key bindings for vscode. So far I haven't found any list of the rules you can add to key bindings (in the when-part). Right now for example, I want to find out if there's a way to make sure a key binding is only active if I have the version control sidebar up and focused. Kind of like:
filesExplorerFocus, terminalFocus, editorTextFocus and explorerViewletFocus.
Since there is a command for setting the focus to the version control sidebar: workbench.view.scm I've experimentally tried scmFocus but to no luck.
Now this is a specific problem, but I'd really like to save myself some time and just be able to run a few ctrl+f through a document of all possible when-rules.
Vscode when clause commands. I only found it through this issue - so there may be a few other undisclosed when clauses: when clause disclosure issues. I see nothing for when the version control sidebar is active though. Perhaps ask about it at that issues page above.
See also https://stackoverflow.com/a/65584576/836330 and especially https://stackoverflow.com/a/65584576/836330

Controlling VS code with a launchpad

I really enjoy using vs code but there are some many shortcuts to remember and every new plugins come with a new set.
Of course, I can use the command palette in order to quickly execute a command, but I would like something even more faster such as assigning a shortcut to any of the keys for a device like a Novation Launchpad midi controller.
Stackoverflow is maybe not the best plase to ask this question but I didn't knew where to post it, so is there anyone who tried something like this? I have seen this video (https://www.youtube.com/watch?v=LOyNUGS4RC8) linking such a device with visual studio so perhaps someone created a software dedicated for vs code already.
Regards,
Johnny -
I've setup this with MIDI Loupe and midiStroke.
MIDI Loupe listens your device and logs channel/key/value you just hit on your midi controller - with this tool you inspect your device's output.
Then in midiStroke you map controls to shortcuts.
Note: I've found my midiStroke setup for M-Audio Axiom 49 keys don't require values (only key number) but controls (e.g. record start) do require it. Also for me letter keys didn't not work if uppercased (e.g. for garageband recording start I need simply R button hit and R should be r in this case)
Detailed tutorial here

How do I run an external command on the current selection in VS Code?

I'm currently switching editors from Vim to VS Code. One feature I like in vim is the ability to run an external command on a region of text (the :! command). I've been unable to find an obvious equivalent in VS Code.
Is this feature available in VS Code? Or is there an extension that provides it?
(As a more general question, what's the best way of finding out things like this? Is there a website or anything that describes how to do common tasks from other editors in VS Code?)
For the record, VSCodeVim allows you to do the same thing.
Having searched some more (the key term is "filter the selection") I found the Filter Text extension, which does exactly what I want.

VSCode all autocomplete

Can VSCode's Intellisense/autocomplete be configured to work across all open files similar to Sublime's All Autocomplete plugin? Is there an extension that supports this?
Specifically, I am looking to get basic function and variable name autocompletion to work across C, C++, Matlab, and Python source files.
No, this is not possible. All actions in VS code are strictly limited to the document, which is passed in to the various APIs an extension has to implement.
I can imagine a hack, however, where you store code completion info persistently (in vscode settings, external file etc.), once you have collected them for a document and use that persistance layer to load all the info from there. This is however not very dynamic and requires that a file has been scanned for code completion info at least once (i.e. it was open in vscode and active at least once).

Eclipse debugger for GEF editor

I have a GEF editor which represent a finite state machine. Editor's input (and output) is XML. What I am looking for is a way to debug my editor visually.
The way editor works is you create a state Start->Email->End, XML that is created is send to the server and there magic happens, of course Email object has properties that you set: from email, to email, subject, etc. What I am looking for is a way I can launch a debugger and step through each step of execution. So for example if I break at Email step I would be able to see what message was, whom it was for and what server returned at the end.
Is this something that is possible to accomplish and if so are there any articles I need to read to familiarize myself with how to create this debugger?
I found some discussion about Eclipse debuggers (1,2) but nothing about what I am interested in doing.
There are two different issues here.
One is writing a debugger engine, that manages the execution of your model, for example steps the execution, allows querying the variables/states, etc., and another one that outputs the result in your editor.
The articles you have linked work with the first issue: creating an engine that executes the model in the background, and integrates the engine into the Eclipse environment using 1) the launch framework to execute it similarly as Java programs, and 2) allows displaying the state in the textual editors.
You want to display the state in graphical editors. Because graphical editors have much less in common, the back-annotation of the debug state has to be done manually (instead of the generic support for text editors). Basically, I would create actions that set up breakpoints, and update the model to be able to store/query the execution state, and then update the GEF views to display it on the GUI. For this you have to change your Figures and your EditParts at least, and possibly other places as well.