Reputation: 335
In PyCharm 2018.2.5 (Community Edition), I have bound a keyboard shortcut to "Run File in Console". This launches opens the console and runs the file, but does not focus the console for input and anything I type goes into my code. (Sometimes when I use the switcher to focus the Python console it will try to search console variables when I type.)
Is there a way to automatically focus the Python console for input when it is launched?
Upvotes: 9
Views: 3666
Reputation: 33
I found the option to do this in Run/Debug Configuration. There is "Modify options" which has "Focus run/debug tool when started"
This is with PyCharm 2023.2.5 (Community Edition) on macOS
Upvotes: 1
Reputation: 1
Within the 'Execute NppExec Script :
Example :
NPP_CONSOLE 0
NPP_SAVE
NPP_CONSOLE 1
cd "$(FULL_CURRENT_PATH)"
C:/dev/Python/Python3/python.exe -u "$(FULL_CURRENT_PATH)"
Upvotes: 0
Reputation: 1
It's very easy! Just make macros with two actions:
1 - Run command,
2 - Activate run tool window. And with keymap in settings create a shortcut. For example, I do this with shift + f10
.
Upvotes: 0
Reputation: 31
Yes it IS possible
import pygetwindow as gw
win = gw.getWindowsWithTitle('Run')[0]
win.activate()
now it will automatically give focus to the run window... see my youtube demo.. https://www.youtube.com/watch?v=MhmltlUjU3k
Upvotes: 1
Reputation: 146
i have just posted something related to this. It is needed to distinguish between "Python console" and "python or debug console" within the keymap options. The first one focus at the console but without automatically move caret to it, the later does it.
See more detailes in this answer.
Upvotes: 0
Reputation: 63
No for PyCharm there is no way to automatically focus the Python console for input when it is launched.
In Notepad ++ i can do the following.
So the step between writing the code and executing it to see what it does exactly one hotkey. Its not one hotkey and a mouse click or what ever no.... its exactly one press of a button. This makes learning very effective because there are no detours.
I looked long in PyCHarm but i could not find this functionality or a workaround. So the answer to your question is "With PyCharm this is not possible."
Here is how to do it in Notepad ++.
Create the "save and run in python" macro: In NppExec create a script as shown here:
NPP_CONSOLE 0
npp_save
npp_run cmd /K C:\Python27\python.exe "$(FULL_CURRENT_PATH)"
Another editor that offers you this quick and direct run functionality is "Atom" with its many plugins.
Upvotes: 4
Reputation: 100
The shortcut to switch between the code and console is Alt+4
; by clicking on the console or using this shortcut, future consoles you open will be selected by the input.
Upvotes: 2