How to check if a key is being pressed right now - events

All:
I wonder how can I detect a key holding in the browser. For example:
I have a DIV on the page, and when I press ctrl key, then I can drag it around on the page, right now, I have implement the drag part, but how to enable that drag only when I hold ctrl key?
Thanks

You didn't specify any languages, so a general solution:
You can use a boolean value, and listen for the keyup and keydown events for the body.
In these events, toggle the value of the boolean value. This way you can always check if the key is pressed by accessing the value of the boolean.

Related

GTK4 under rust, trying to find which mouse pointer and whether there are modifer keys pressed

I'm writing a gtk4 application in rust, and I'd like to get the mouse key that was clicked and any modifier keys at the time. My GestureClick handler has .buttons(0) to accept input from all buttons, but the event object does not seem to have any way to determine the source of the event. The event just gives the GestureClick object, location, and click count. Does it need to have a separate handler for each button?
In addition, I'd like to use modifier keys like shift and ctrl to modify the action. This does not seem to be available (at least, I haven't been able to find it). Would I need to monitor keypress events to keep track of the state myself? I'm pretty sure X reports the state of the modifier keys on click events, gtk doesn't?
Thanks

Continuous key press event in Silverlight application

I am making application using silverlight.Here i want to move line on screen continuously on left and right arrow key pressed. In silverlight application there is facility of RepeatButton but i am not getting how to use it. Please help me if there is any solution on that.Thanks in advance.
An easier method would be to have (bool) flags like "keyLeftPressed" and "keyRightPressed". Then, on a specific tick (from a DispatchTimer possibly), check if the flags are set and take appropriate action. Finally, use four events to set the condition of the two flags: left key pressed, left key released, right key pressed, right key released.

Debugging with Key Pressed

I have a function that displays an object on screen when a key is pressed. I should be able to left click this object while the key is pressed and the program makes a change to the object on the click - this is not happening. I put a breakpoint into the left mouse click handler. Pressed the key and clicked the object. Switching to VS2010 I get a message that I cannot Edit and Continue at that point. If I lift off the key press then I can debug. However I am concerned that there may be something else reacting to the key press causing the change in the object to fail.
A quick update - if I disable the actions from the Key Up event then everything works.
My question is therefore if there is any way to debug in VS2010 with a key pressed.
Thanks
Use Tracepoints. This will allow you to add trace messages and output the value of variables without needing to stop in the debugger. Key presses and mouse clicks will therefore not interfere with the debugger.

How to determine the value of key pressed in Windows Phone 7 Numeric Keyboard?

I hooked up an event handler to the KeyDown event of a TextBox. The event handler has an argument of type KeyEventArgs with properties Key and PlatformKeyCode. The issue is for both the 1 and ! keys pressed on the windows phone soft keyboard, the values for Key and PlatformKeyCode are D1 and 49 respectively. I cant tell which key was pressed. Also the Keyboard.Modifiers static property returns "None"
So how do I determine the key that was pressed?
This is a known issue.
KeyDown/OnKeyDown and KeyUp/OnKeyUp issues
You could always read the input values instead and act on 1 / ! seperately.
This very much looks like a bug.
This exists on both the emulator and real devices.
If using the pc keyboard with the emulator the modifier keys are detected on key down so this won't work.
Interestingly, if using a device with a physical keyboard, if the function/shift button is enabled it triggers 2 keydown events when the other button is pressed. One for the correct keycode and one for the modifier key but Keboard.Modifier always equals "None".
It looks like you need to read the textbox value before and after the TextChanged event.

Programatically triggering tab key functionality in a VB.Net windows application

How can I programatically trigger the tab key functionality in a VB.Net windows application?
Currently in my application I am using one splitter when I press the tab key, and the focus is moving in the right order.
However I need to use arrow keys to move the focus to next controls, in the same way that the focus is going when the user presses the tab keys.
Thanks in Advance
You can simulate the SendKeys.Send(string) method (in the Systems.Windows.Forms namespace). To simulate a tab keypress you would call SendKeys.Send("{TAB}").
To see all the key codes, check out http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
Better late, than never, since i found this post looking for a solution to a similar problem.
Windows Form type has ContainerControl somewhere in its chain of inheritance and that has a method ProcessTabKey(Boolean trueForForward) . It does exactly what you need, inside your form instance this.ProcessTabKey(true) will move focus forward along the tab index and this.ProcessTabKey(false) will move it backward.
Very simple code
Write Down this in KeyDown Event of Datagridview
If e.KeyCode = Keys.Enter Then
' Your code here
SendKeys.Send("{TAB}")
e.Handled = True
End If

Resources