Powershell ISE addon working when using GUI menu but not when using its assigned custom keyboard shortcut - powershell

I still use the ISE on occasion and decided to attempt a custom ISE addon that emulates VS Code's Delete Line Ctrl+Shift+K keyboard shortcut. For the moment, this rough draft doesn't delete multiple lines if selected (that functionality will be added later), only the line the cursor is on:
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Delete Line", {
$psise.CurrentFile.Editor.SelectCaretLine()
[System.Windows.Forms.SendKeys]::SendWait("{DEL}")
[System.Windows.Forms.SendKeys]::SendWait("{DEL}")
}, "Ctrl+Shift+K")
What I discovered is that this runs as intended when using clicking on the ISE's menu (Add-ons > Delete Line) but not when using its assigned keyboard shortcut (Ctrl+Shift+K). Using the keyboard shortcut runs everything I've put in the code block thus far except the SendWait() method(s).The result when using the keyboard shortcut is what you would expect $psise.CurrentFile.Editor.SelectCaretLine() to do - highlight the line that the cursor is currently on - it just doesn't send 'Delete' twice. The console output is identical when using either method (GUI vs keyboard shortcut). I've run into some goofy things when using Winforms classes within the ISE, but the difference in behavior between using the ISE Add-ons menu vs keyboard shortcut is new to me. I've googled for PowerShell ISE SendKeys and ISE SendWait etc and have come up empty.I'm open to suggestions on a better method (regex, pinvoke/embedded Win32, etc) but am hoping to gain some insight into what's happening under the hood within ISE.I know, I know - I already use VS Code for a lot and ISE is dying, but this has me curious now and I'd like to know either how to fix this or at least understand why the SendWait method isn't playing well with the ISE.Any help is much appreciated!

*** removing my previous answer, since you had issues with the approach.***
Refactoring to just this, fully tested/validated for what you say you want. I'd still work to avoid Send-Keys, unless there is no other option.
Function Delete-Line
{
$psISE.CurrentFile.Editor.SelectCaretLine()
# Pause the allow for Send-Keys to work for HotKey use
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait('{DEL}')
}
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Delete Current Line", {Delete-Line}, 'Ctrl+Shift+K')
You of course can adjust that time to fit your response time. Say, using milliseconds vs seconds. This timing is not absolute with Send-Keys. Each machine you use this on may need a time adjustment. Hence the reason to use another more efficient approach.

Related

CLIPS: Clear-window in CLIPSDOS.exe and tab to indent in CLIPSIDE

With CLIPS, It's possible some of the following?? (V 6.4 for Windows)
1 - Use a command like (clear-window) in the CLIPSDOS console for clear the console.
2 - Use tabs for indentation in CLIPSIDE. When i press tab, cursor goes to File menu item... how to indent?
How do people learn programming with CLIPS? I'm using a plugin for Visual Studio that helps me with the parenthesis concordance, let me use tabs to indent, and other tricks. But it has some problems, and i'm quite worried about the usability of the CLIPSDOS and CLIPSIDE interfaces to this purpose.
Thanks in advance.
In CLIPSDOS, you can use the command (system cls) to clear the screen. This will simply call out to DOS to execute a cls command.
The IDEs use standard text editing classes for the CLIPS command prompt window. Tabs appear to work correctly on the macOS IDE, but not the Windows or Java Swing IDEs, so that will need to be corrected.
While you can directly enter constructs at the command prompt, it's better to edit them in a file with your preferred text editor and then use the load command from the command prompt to load the contents of that file. The IDE supports a command history so you can use the up/down arrow keys to cycle through prior commands to avoid retyping.

VS Code with Vim extension: ctrl+d does not go half a page down but instead goes to "Select Environment"

I checked VS Code shortcut bindings, but do not see why "ctrl+d" will open "Select Environment" instead. That does not even appear in the shortcut bindings. Any idea how I can make it go half a page down instead?
I'm assuming you're using the Vim extension and expect it to page down.
If you select one of the environments (like Node.js for me), it should work after.
In case someone ever met this problem again, I solved this problem by entering command mode (press :) and escape.
I still am not sure what happened.

Run Power Automate flow from Windows Desktop via shortcut key or command line / shell

I would like to run a Power Automate flow by pressing a keyboard shortcut or alternatively calling it up from CMD or Powershell script.
The flow would simply start execution once the keyboard shortcut is pressed or a Powershell script is run.
As it is now; I need to start Power Automate and then click on play in order to start a specific flow. I am trying to avoid all that.
The ultimate goal is to, once the system is up (Windows 10) and I'm logged it, I press the shortcut key and go do something else and by the time I get back the flow is done. The flow itself works flawlessly. Please note that I am not looking for a solution which would involve smartphones and flow buttons on said phones, purely a Windows , PC, only solution or a way to a solution.
Here is a picture to clarify what Lukas was describing as a workaround.
Create a loop and make sure that the index variable for the loop is 0 so that it will never stop looping. Then make sure to put a 'wait for shortcut key' inside of the loop with you desired shortcut. Below that action and still inside of the loop, put all of your actions.
Run the script and the script will enter the loop at the 'wait for shortcut action. When the shortcut is pressed it will run all of the actions and then loop back to the 'wait for shortcut action again. As long as the script is running in the background the shortcut can trigger it.
Surprisingly, I do not think there is a way to do this. The best solution would probably be to use AutoIT to create a small automation to start your PAD flow.
As long as you're somewhat familiar with programming and even if you're not familiar with AutoIT, it shouldn't take you but a couple hours to write a script that is activatable via hotkey that opens PAD and starts the flow you want.
The AutoIT help file that you get when you install should be all the guidance you need.
(Depending on what your flow actually does, you might be better off just writing your whole automation in AutoIT)
You actually don't need to put everything in a loop, the loop is just from the end of the script to the top label. You just need a label at the top (if you want to be able to press the shortcut more than once), a wait for shortcut key event, and at the end a "go to the label" you created (in the image below it's 'start').
Then you can save the flow and start it. Nothing will happen until you press your shortcut key. Then the flow will execute, and return to the top, waiting for you to press your shortcut again.
You can even have errors go to the start label, instead of ending the script, so that the flow "stays alive".
Just put label on top of your code and then "Wait for shortcut key" and at the end use "go to" function, that will loop the code. This works for me

Configure VS Code output window for python to jump to last line of output window?

I am sorry if the question doesn't make sense, I didn't really know how to phrase it properly.
What I am trying to achieve is similar to how it works in the command prompt when running a python file. When I run a python file from the command prompt, the command prompt window will jump to the last outputted line during the running of the program, so what is currently being outputted is always visible. However in my current VS Code set up, the output window will not jump to the last line as it is printed, and I have to scroll through the output window to see what is happening with the program.
I am currently using the latest version of VS Code and using the code-runner extension as well. Please let me know if what I am asking does not really make sense.
Thanks
As far as I understand your question, I would like to answer it.
To Auto-Scroll to the last output, you can just click on the Lock Icon near the Clear Console icon.

Does VS Code has any shortcut like ctrl+q in eclipse?

Does VS Code (I currently use v1.8.1) has any shortcut like ctrl+q in eclipse?
It returns your cursor to the place where you stopped writing code(very useful for fast code browsing)
and it is different to alt+left which navigate backward
EDIT: I have found that this extension should do that you're asking. I suggest trying it out.
Original:
Out of the box in VS Code, this command does not exist. The list of default shortcuts can be found here, or you can open the keybindings settings in VS Code (ctrl+k, ctrl+s on Windows) and see which commands are available.
If you'd like to suggest this as a feature, you can open a new issue on GitHub or consider creating an extension.
If I understand correctly, you want a command that will move the cursor to where the last edit in a document was made.
This should be possible using an extension that listens to document change events and records the position of the cursor. Then, when the command is issued, it sets the editors cursor to that saved position.
You can also try "Eclipse Keymap" from Alphabot Security, has a lot of eclipse bindings.
I don't believe there is a built-in way to do this, but you could work around it by using an extension such as https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks .