Visual Studio Shortcutkeys - visual-studio-2010

I was working on a project, and while pressing some shortcut keys, I noticed the status bar of Visual Studio 2010:
Please try some shortcuts yourself to notice the whole behavior of VS, and then...how could I achieve that effect at the same level of performance? Thanks in advance!
P.S. I have the following code block taken from Stack Overlow, that does something like that but not the same performacnce level. My code works for CTRL + K, P.
protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
{
if (prefixSeen)
{
if (keyData == ( Keys.Control | Keys.P))
{
MessageBox.Show( "Got it!" );
keyComb.Text = "Ready";
}
prefixSeen = false;
return true;
}
if (keyData == ( Keys.Control | Keys.K))
{
prefixSeen = true;
keyComb.Text = "CTRL + K was pressed. Waiting for a second chord of keys...";
return true;
}
return base.ProcessCmdKey( ref msg, keyData );
}
But after pressing CTRL + K The label keyComb does not take the value "CTRL + K was pressed. Waiting for a second chord of keys..."
Code taken from: How to get a combination of keys in c#

Related

Detect if the keyboard layout has AltGr on it under Windows

Does anyone know a good method how we can check from code in C/C++ if the actual keyboard layout has the ALTGR key or not on it?
I think the best method would be to read and interpret the keyboard layout file e.g. "KBDGR.DLL" for german but the API to do this does not exists and that what exists is not well documented.
Is there any other way to do this?
I know it's been a while - This is the best I came up with
BOOL CMonitor::LayoutHasAltGr(HKL keyboard_layout)
{
BOOL hasAltGr = FALSE;
int scancode;
for (WORD i = 32; i < 256; ++i)
{
scancode = VkKeyScanEx((TCHAR)i, keyboard_layout);
if (scancode != -1 && (scancode & 0x600) == 0x600)
{
// Ctrl + Alt means AltGr
hasAltGr = TRUE;
break;
}
}
return hasAltGr;

OpenCV works slow in Microsoft Visual Studio Community 2017

I am trying to work with webcam using C++ and OpenCV in Microsoft Visual Studio Community 2017, but it works very slow(I can't see any changes in video - only one frame). Although the same functions work fine in Python. How can I solve this problem? Thanks.
Mat frame;
VideoCapture vid(0);
if (!vid.isOpened())
{
return -1;
}
else {
while (vid.read(frame))
{
imshow("Video", frame);
if (waitKey() >= 0)
{
break;
}
}
}
return 0;
The problem is the condition waitKey() >= 0.
Change the code to:
Mat frame;
VideoCapture vid(0);
if (!vid.isOpened())
{
return -1;
}
else {
while (vid.read(frame))
{
imshow("Video", frame);
int key = waitKey(1);
if (key == 27)
{
break;
}
}
}
return 0;
waitKey waits the specified time (1) for a key press. In this example we store the value in "key" and if it matches the ascii value 27 (esc key) the program ends.
Why your code does not work:
Your program doesn't seem to work because using waitKey() in C++ it is interpreted as waitKey(0) which will wait forever until some key is pressed (0 means infinite waiting). And when a key is pressed the if sentence (>=0) will become true (because the ascii value of the key pressed will be greater or equal than 0), so the program will exit.

Allegro 5 detects long key press as several key presses

In the code block below I am trying to move a rectangle once for every key-press but the rectangle moves as long as I hold down a key.
ALLEGRO_EVENT ev;
while(!done)
{
al_wait_for_event(event_queue, &ev);
if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
{
switch(ev.keyboard.keycode)
{
case ALLEGRO_KEY_UP:
pos_y -= 10;
break;
case ALLEGRO_KEY_DOWN:
pos_y += 10;
break;
case ALLEGRO_KEY_RIGHT:
pos_x += 10;
break;
case ALLEGRO_KEY_LEFT:
pos_x -= 10;
break;
}
}
else if(ev.type == ALLEGRO_EVENT_KEY_UP)
{
if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
done = true;
}
al_draw_filled_rectangle(pos_x, pos_y, pos_x + 30, pos_y + 30, al_map_rgb(255,0,255));
al_flip_display();
al_clear_to_color(al_map_rgb(0,0,0));
}
Also I noticed that al_wait_for_event is not waiting for a new event in case of holding down a key but is in fact making the event of type ALLEGRO_EVENT_KEY_CHAR . Although this should not pose any problem , I wanted to know a bit more about it.
Also, the above code is taken from a tutorial. It worked fine over there.
To make sure your app doesn't apply the key press more than once per Key_Down event define a Boolean initialized to false. Place everything in your Key_Down events in an If statement triggering only if Boolean == false and in its block immediately set Boolean = true followed by the things you want the event to do only once per event.
Then, in the corresponding Key_Up event set
Boolean = false and you should be golden.
I haven't tested this, but it should work, and it serves towards compating your app to any client computer, no matter if they have funky key press settings on their device.

Cant split left control and right alt in polish language

I setup "polish-programmers" keyboard layout
I try to:
HKL hkl=GetKeyboardLayout(0);
for(unsigned long ch=0x20; ch<=0xff ; ++ch)
{
int v = HIBYTE(VkKeyScanEx(ch,hkl));
if(v==6){
return (GetKeyState(VK_CONTROL) & 0x8000) &&(GetKeyState(VK_RMENU) & 0x8000);
}
}
return false;
I made test with GetKeyboardState - same result: always left control have same flags as right alt(altgr)
May be somebody have workaround?

Hotkeys for Previous and Next call stack frames in Visual Studio

Visual Studio gives many navigation hotkeys:
F8 for next item in current panel (search results, errors ...),
Control+K, N for bookmarks,
Alt+- for going back and more.
There is one hotkey that I can't find, and I can't even find the menu-command for it, so I can't create the hotkey myself.
I don't know if such exist: Previous and Next call-stack frame.
I try not using the mouse when programming, but when I need to go back the stack, I must use it to double click the previous frame.
Anyone? How about a macro that does it?
I wrote 2 macros to gain it: PreviousStackFrame and NextStackFrame and assigned shortcuts to
Function StackFrameIndex(ByRef aFrames As EnvDTE.StackFrames, ByRef aFrame As EnvDTE.StackFrame) As Long
For StackFrameIndex = 1 To aFrames.Count
If aFrames.Item(StackFrameIndex) Is aFrame Then Exit Function
Next
StackFrameIndex = -1
End Function
Sub NavigateStack(ByVal aShift As Long)
If DTE.Debugger.CurrentProgram Is Nothing Then
DTE.StatusBar.Text = "No program is currently being debugged."
Exit Sub
End If
Dim ind As Long = StackFrameIndex(DTE.Debugger.CurrentThread.StackFrames, DTE.Debugger.CurrentStackFrame)
If ind = -1 Then
DTE.StatusBar.Text = "Stack navigation failed"
Exit Sub
End If
ind = ind + aShift
If ind <= 0 Or ind > DTE.Debugger.CurrentThread.StackFrames.Count Then
DTE.StatusBar.Text = "Stack frame index is out of range"
Exit Sub
End If
DTE.Debugger.CurrentStackFrame = DTE.Debugger.CurrentThread.StackFrames.Item(ind)
DTE.StatusBar.Text = "Stack frame index: " & ind & " of " & DTE.Debugger.CurrentThread.StackFrames.Count
End Sub
Sub PreviousStackFrame()
NavigateStack(1)
End Sub
Sub NextStackFrame()
NavigateStack(-1)
End Sub
I have solved this problem with AutoHotkey. I made this a few months ago.
Suppose you wanted to use Control+1 and Control+2 and that Control+Alt+C is bound to showing the Call Stack window:
^1::SendInput !^c{down}{enter}
^2::SendInput !^c{up}{enter}
It seems to work pretty well. If you aren't already using AutoHotkey to show Visual Studio who's boss, please give it a shot. Your question indicates that you would benefit greatly from it. It's a game changer. Good luck.
I don't think theres an explict next-frame / prev-frame key binding but heres what I do.
CTRL-ALT-C is already bound to "Debug.CallStack"
This will focus you in the Call Stack Tool Window
Once focused in the Callstack window... Up & Down arrows will move you through the call stack frames
I've then bound
CTRL-C, CTRL-S to "DebuggerContextMenus.CallStackWindow.SwitchToFrame"
and
CTRL-C, CTRL-C to "DebuggerContextMenus.CallStackWindow.SwitchToCode"
both of which will take you back into the code window at the particular frame.
Hope that helps.
Huge thanks to #Oleg Svechkarenko for his answer that gave me a starting point in crafting this solution. Since modern versions of Visual Studio no longer have official macro support, this should drop in for those who use the Visual Commander plugin, but probably can be easily adapted for any other macro extension.
Here is the code for the command, I created one for navigating up the call stack and one for navigating down with the same code except the parameter passed to MoveStackIndex(), then bound keyboard shortcuts to them:
using EnvDTE;
using EnvDTE80;
using System;
public class C : VisualCommanderExt.ICommand
{
enum MoveDirection
{
Up,
Down,
}
private bool IsValidFrame(StackFrame frame)
{
string language = frame.Language;
bool result = (language == "C#" ||
language == "C++" ||
language == "VB" ||
language == "Python");
return result;
}
private void MoveStackIndex(EnvDTE80.DTE2 DTE, MoveDirection direction)
{
StackFrame currentFrame = DTE.Debugger.CurrentStackFrame;
bool foundTarget = false;
bool pastCurrent = false;
StackFrame lastValid = null;
foreach (StackFrame frame in DTE.Debugger.CurrentThread.StackFrames)
{
bool isCurrent = frame == currentFrame;
if (direction == MoveDirection.Down)
{
if (isCurrent)
{
if (lastValid == null)
{
// No valid frames below this one
break;
}
else
{
DTE.Debugger.CurrentStackFrame = lastValid;
foundTarget = true;
break;
}
}
else
{
if (IsValidFrame(frame))
{
lastValid = frame;
}
}
}
if (direction == MoveDirection.Up && pastCurrent)
{
if (IsValidFrame(frame))
{
DTE.Debugger.CurrentStackFrame = frame;
foundTarget = true;
break;
}
}
if (isCurrent)
{
pastCurrent = true;
}
}
if (!foundTarget)
{
DTE.StatusBar.Text = "Failed to find valid stack frame in that direction.";
}
}
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
if (DTE.Debugger.CurrentProgram == null)
{
DTE.StatusBar.Text = "Debug session not active.";
}
else
{
// NOTE: Change param 2 to MoveDirection.Up for the up command
MoveStackIndex(DTE, MoveDirection.Down);
}
}
}
Look in Tools->Options->Environment->Keyboard. Enter "stack" or "frame" and related menus will appear. It seems that there's no next and previous call-stack frame.

Resources