How Can I Create a Visual Studio Macro to Change the Keyboard Layout?

扶醉桌前 提交于 2019-12-06 16:08:48

问题


Is it possible to create a Visual Studio (2010) macro to change the keyboard layout?

I find the "copy and paste from other applications" bug in Emacs Emulation Mode a bit annoying, so what I wanted to do is create two simple macros - one to set keyboard layout to the Emacs keyboard layout, and one to switch the layout to default (I'm sure there would be an easy way to combine them into "switch between the two", but I wanted to start simple).

Not knowing much about VS macros, I figured I could just employ the "hit record and click around" development methodology.

Unfortunately, hitting record and clicking "Tools > Options", then clicking "Keyboard", then clicking the layout combobox and selecting "Emacs" results in the following one line of code:

DTE.ExecuteCommand("Tools.CustomizeKeyboard")

Furthermore, ExecuteCommand seems to wait for the user to close the window before continuing with the execution of the macro, so I can't immediately see how to tell Visual Studio "click the combobox, select the FizzBot item", etc.

Can this be done? If so, how?

Thanks in advance.


回答1:


The macros are:

Sub SetDefaultKeyboard()
    DTE.Properties("Environment", "Keyboard").Item("SchemeName").Value = "(Default)"
End Sub

Sub SetEmacsKeyboard()
    ' change "Emacs" to actual keyboard layout name
    DTE.Properties("Environment", "Keyboard").Item("SchemeName").Value = "Emacs"
End Sub

You can assign a keyboard shortcut or a toolbar button for them.



来源:https://stackoverflow.com/questions/5120537/how-can-i-create-a-visual-studio-macro-to-change-the-keyboard-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!