I am getting an error with key bindings when I search within a VS Code (command F on Mac) notebook. When I hit enter the cursor remains in the search bar & text is highlighted. If I wanted to clear the search bar and hit 'delete' (backspace equiv), I get a chord message '(Backspace) was pressed. Waiting for second key of chord.."
However, if I look into keyboard shortcuts I find I actually do not have ones that begin with that key. Here is the screenshot of keyboard shortcuts with 'recording' turned on to get all that start with 'delete'
Anyone know what is going on here or how to fix this?
After pressing Ctrl+Shift+P, search for Toggle Keyboard Shortcuts Troubleshooting. This will log you the keyboard events. You may for example be pressing Backspace without Ctrl being up again, and this logs will show you the keybindings that caused this chord message.
After finding the keys that caused the chord, go to settings and find the other bindings.
If you can't find it, you may try going to a random command, double click it and press on the keys that you found as the cause of the chord. VS Code will tell you the other commands with the same key bindings, at the bottom of input pop-up. Click on it and find the other binding.
If these still don't work, an extension that you installed may cause this problem, but I don't know the solution in that case.
Related
When I try to select all of the text in a file, I receive a notification that says:
(Ctrl + A) was pressed. Waiting for second key of chord...
Here is a screenshot of my "select all" keyboard shortcuts. How can I use Ctrl + A to select all text instead of getting a chord notification?
You have another key binding that begins with Ctrl+A, something like this:
A sequence of multiple keystrokes pressed one after another (rather than simultaneously) is called a "chord".
You might have accidentally created it, or might have recently installed an extension that adds the problematic binding. To find it, do like I have done in the screenshot and type "ctrl a" into the Keyboard Shortcuts search box (that tab can be opened by typing Ctrl+K then Ctrl+S). Then look for a binding that begins with Ctrl+A but has something else after it (in my case, another Ctrl+A, but it could be almost anything).
When you find the offending binding, right-click on it, and either remove or change it. Then Ctrl+A alone will resume working.
Note: This question and its answer pertain to Visual Studio Code, which is different from Visual Studio. See this question for information about the equivalent situation in Visual Studio.
You might be in a situation where you want to keep the chorded keybindings that are causing you the problem with your original keybinding. A potential workaround to this issue is turning your original keybinding into a chord as well. For example, you could having a 'stop' character that exits your chord. For example, "Ctrl+A ." where "." is your stop character.
So if for some reason you really liked "Ctrl+A" as the beginning keystroke for a bunch of chorded keybindings, then rebinding all current "Ctrl+A" keybindings to "Ctrl+A ." would free up that keystroke for any manner of other, chorded keybindings.
I was in a situation where Ctrl+x did not work and was considered the start of a keychord. Every time I pressed Ctrl+x, instead of cutting the selected text, the editor told me that it was waiting for the second key of the chord.
Looking at "Preferences->Keyboard shortcuts" did not help. Searching for Ctrl+X in the list showed that only the "Cut" command was mapped to this key.
I had to edit the file $HOME/.config/Code/User/keybindings.json (under Linux) and search for CTRL+x. It turned out another command was mapped to a keychord starting with this key combination. I am not sure know how I got in this situation.
In my case, reloading VS Code with extensions disabled fixed it, so I knew it was an extension. Took a while, but eventually figured out it was https://github.com/phsantos/nano-id-generator.
I'm making a key press overlay for rhythm games. How would I go about obtaining keyboard inputs outside of the Python window's focus?
I would assume you would use the keyboard module, but I can't find any documentation on it other than how to have it record and simulate key presses. Upon importing it and looking at possible functions, I see that there are some that appear to have the functionality of getting keys down/up. I have no idea how to use them though. I'm not sure if I'm even on the right track with the keyboard module but maybe one of you guys know.
I am trying to write some code to repetitively clear the console and output a message, whenever I press a key that is added to the console as if I am in an input() state, when backspace is pressed the last letter is deleted. I also want to add a "cursor" so that when pressing arrow keys the characters selected move left and right. Everything works as expected except for the arrow keys.
So I scoured the internet for any information on this. I found 1 post, 3 years ago. It is inactive and no answer was given. The post is here. It is very similar to my question but rather then detecting a press I need to stop random outputs coming out. I am using Python 3 with Windows.
This issue happens exclusively when using the Keyboard module and when detecting arrow presses. If I do not detect the arrow presses this does not happen even when importing the module. My code is as follows:
if keyboard.is_pressed("left"):
# at this point a "4" is outputted into the console and detected when it wasn't pressed
Similarly with up arrow "8" is outputted, with down arrow a "2" is outputted, and right outputs a "6". This obviously sounds ridiculous but the post I linked above (being the only occurence I have ever read about this) clearly describes this identical problem.
They only wanted to differentiate between a 4 being pressed and a left arrow being pressed. By using keyboard.hotkey or keyboard.on_press_key, both of which I tried, there were no differences in results.
This should be extremely easy to reproduce, but I would be interested to know if anybody was unable to reproduce this and if it is linked to a specific OS or version of Python. I experienced this same problem a few years ago and quickly gave up on the mini project, now I'm re-experiencing this problem, if there is another way that I can have a function run or detect if an arrow key is currently being pressed down without these numbers being outputted, that would be a solution to this.
I have a program in Python that starts another executable. Some automated operations need to be done in the ribbon of this open executable, so I use pyautogui to do so.
First the ribbon needs to be ‘active’, so I click on the left most part.
Then I need to use the arrows to change the ribbon menu selection (two times to the left).
Then I need to hit enter to open the correct menu. (going from 'File' to 'Scripting')
The code I’m using for this is:
import pyautogui
pyautogui.click(x=0, y=30)
pyautogui.press(['left', 'left']) #this part does not work here
pyautogui.hotkey('enter')
Somehow, the click and enter do work, but the arrow-keys don’t work. I can use the physical arrow-keys to change the menu selection, but this code doesn’t perform these actions somehow.
Does someone know what is wrong here and how to solve this?
Best regards,
Ganesh
EDIT:
I tried to open both the program and the script with admin right, but that still didn't work. Somehow, the 'enter' and everything else works, except for the arrows.
Ganesh, it might not work with pyautogui as the program/ interface you're using might simply not register the key. To use the arrow keys or other special keys like 'enter' I would suggest using pydirectinput
First, install the library if not already
pip install pydirectinput
Then you can rewrite your code as
import pyautogui
import pydirectinput
pyautogui.click(x=0, y=30)
pydirectinput.press(['left', 'left']) #this is the updated line of code
pyautogui.hotkey('enter')
I have to write a script to emulate some keyboard event in a different program in background.This is my code:
pwin = win32ui.FindWindow(None,r'someprograme')
pwin.SendMessage(win32con.WM_KEYDOWN,18)
pwin.SendMessage(win32con.WM_KEYDOWN,68)
pwin.SendMessage(win32con.WM_KEYUP,18)
pwin.SendMessage(win32con.WM_KEYUP,68)
pwin.SendMessage(win32con.WM_KEYDOWN,13)
pwin.SendMessage(win32con.WM_KEYUP,13)
But it seems nothing happened.So what should i do?I've tried PostMessage func it seems it still can not do it.
After a quick look at the WM_KEYDOWN docs:
Posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.
But looking up your keycodes, you're trying to send ALT-D (followed by ENTER, which is fine). It sounds like you're trying to drive the menus; if that's what you want to do, WM_KEYDOWN is not the way to do it.
The problem is that keyboard menu navigation is driven by Windows, not by the app (except for a handful of apps that override normal menu processing, like some versions of Visual Studio). When you're looking at Notepad, and you hit ALT-F to open the File menu, the Notepad code gets a bunch of menu-related messages (WM_INITMENU, etc.), not the keystrokes.
If you use a WM spy program (I think the free Visual Studio Express still comes with Spy++ and ManagedSpy, but if not, search for an equivalent), you can see what the application is actually seeing when you drive it with the keyboard, and then you can figure out how to emulate that from your Python script.
On top of everything else, depending on how the program is written, it may not accept keystrokes when it doesn't have focus.
By the way, if you're just getting started with Windows GUI automation, you might want to look at something higher level, like pywinauto. That way, you don't have to work out what menu-related messages to send to open the Data menu; you just do something like app.Foo.MenuSelect('Data').