Capturing Arrow key keyboard event in windows form - winforms

For Opengl view on windows Form in Visual C++ , Iam completely puzzled about how to represent arrow keys(UP ARROW, DOWN ARROW, RIGHT ARROW, LEFT ARROW) for capturing these 4 keyboard events. For other alphabetic keys i just used....
void PhotoRealisticRendering_KeyPress(Object^ sender, KeyPressEventArgs^ e){
if(e->KeyChar=='D')
{
}
}
Can someone help me with this?

Related

Highlighting text in a Winforms textbox

For a Winforms textbox, when you click and drag over the text, it highlights it. Is there a way to determine which direction the user dragged over?
There is no way to get this info using the Windows TextBox selection API. For example, the EM_GETSEL message defines the starting and ending character positions of the selection, but in a predefined (sorted) order.
However you could get this info by handling the control's MouseMove event. For example:
textBox1.MouseMove += new MouseEventHandler(textBox1_MouseMove);
void textBox1_MouseMove(object sender, MouseEventArgs e)
{
Control tbCtrl = sender as Control;
// the mouse coordinate values here are relative to the coordinates of the control that raised the event
int mouseX = e.X;
...
}
By applying some logic to mouseX you could potentially discover the average direction the cursor is moving. It would work best if the user is making a linear motion. You could also handle the textbox's drag-and-drop event for similar mouse information if you only wanted the event raised while the user was dragging the mouse.

Rotate the DataGrid, how to Rotate the direction / arrow keys

We have rotated our DataGrid by "-90" successfully.
However, The arrow keys stayed as not rotated.
For example, When we press the UP-Arrow-key it goes left, instead UP, etc.
How can we rotate the Arrow keys to reflect the actual directions of the screen?
Thanks much for your help.
Can't imagine what for you've rotated dataGrid, but you can catch the keypress event and transform it to another key press (for example, left transform to up) like in this thread:
Simulating Key Press c#

Alt + Key on Textbox with non-English keyboard should add letter but it doesn't

On a german keyboard you would add [ by pressing Alt+8 and ] via Alt+9. This is not working in a WPF textbox or richtextbox.
When creating a new application and adding textbox, the combinations using the right Alt key are working, not the combinations for the left Alt key.
Adding the textbox to a usercontrol and a toolbar and putting everything inside of a scrollviewer also disables the right Alt key combinations.
My workaround is for now to add an event handler for the previewkeydown event and add the characters code-wise. However, that does not feel right. I assume that I am missing something very basic here but cannot find it. All methods I found lead to a full deactivation of the Alt key functionality. Would appreciate if somebody could give me a hint.
When using the German (DE) Keyboard layout you MUST use the Right Alt key and NOT the Left Alt key and then press 8 or 9.
This is how Microsoft Windows configures other coutries keyboards. The Left Alt serves as the Windows Alt Key while the right is dedicated to special characters.
You need the a "windows" alt key for windows key combinations like Control + Alt + Delete, Alt + Tab, etc.

How to capture mouse coordinates from another program

I'm trying to write a WinForms program that will capture mouse coordinates upon pressing and (more importantly) releasing the middle mouse button.
My form has topmost set to true (so that text in it can always be visible even when it doesn't have focus).
What I'm aiming for is being able to hover the mouse over a game window after my program starts, hit the middle mouse button, and have it record the mouse position for later use.
I can get it to detect when the middle mouse button is clicked inside the form using the MouseUp event (bound to the form itself) but have no clue what I need to do to have it detect when the mid mouse is clicked outside my form.
Thanks for any help guys.
I believe what you are after are called low level hooks. A quick google brings up this: Erroneous Mouse Coordinates Returned from Low Level Mouse Hook C#
A microsoft example of how to do can be found here: http://support.microsoft.com/kb/318804

Silverlight 4 mousewheel press

how can I capture mouse wheel click/press in Silverlight 4? I can detect its rolling using delta in mousewheel event, is there any way to detect its press? I use VS2010/C#
The mouse wheel click would be a middle mouse button event. Unfortunately the middle mouse button is not supported in Silverlight 4. Consider alternatives such as cntrl + left click, especially as many computers won't have a middle mouse button.

Resources