C# Key Down stops firing after right arrow key pressed - keyevent

My team and I made a game version of Snake, and everything works well except after I push the right arrow key, then the key events stop firing. I have tried setting Keyboard.Focus and other focus methods, but it doesn't work.
Our project is on github at: csis2530, look for bbarke.
I don't know why the key down event stops working after the right arrow key has been pressed.
I hope someone could help us.

I fixed the gui by ensuring that the GameWindow has the focus and only the GameWindow has the focus. This is what you do:
Click on the New Game button, go to its property and search for "Focusable". Then UNcheck the Focusable checkbox. Do this for the combobox (the one that has the levels), the high score button, and the apples eaten label, and everything else EXCEPT for the Game Window. Make sure that the GameWindow has the focus and make sure that its Focusable is checked.
I noticed that when I push on the arrow keys, the combo box would change. This is due to the focus from the GameWindow being taken away by the combo box.
So make sure that only the GameWindow has the Focusable property checked.

Related

wxWidgets pprogrammaticaly move to next input control

I originally had code that set the focus to the first widget in a dialog, in the onInit method. But there were problems with it: if I pressed TAB, indeed focus moved to next control (wxTextCtrl), which got the blue 'focus' color, but the 'focus' color/highlight was not removed from previous focus widget. So now it looked like both first and second control had focus at the same time...
When cycling manually (by pressing TAB) full circle (till last control and then wrap around to the first), suddenly all worked well. That is, when moving focus from first control to next one, the first visually lost focus (blue color was removed) as it should. From now on, only one item had the focus color/highlight.
So instead of setting focus on the first control, I tried a different approach: I set the focus to the last control in the dialog, which is always the OK button. Next, I want to emulate programmatically that a TAB is pressed and received by the dialog. So I wrote this (inside Dialog::onInit):
m_buttonOK->SetFocus();
wxKeyEvent key;
key.SetEventObject(this);
key.SetEventType(wxEVT_CHAR);
key.m_keyCode=WXK_TAB;
ProcessWindowEvent(key);
Now the focus indeed moves away from the OK button, but it does not wrap around to the first control.
Only when I manually press TAB after the dialog opened, the first item gets focus.
Question: why does this wrapping around to set focus on first widget not work with the code shown above?
First of all, your initial problem is almost certainly related to not calling event.Skip() in one of your event handlers, see the note in wxFocusEvent documentation.
Second, you can't send wx events to the native windows, they don't know anything about it. In this particular case you can use wxWindow::Navigate() to do what you want, but generally speaking what you're doing simple can't, and won't, work reliably.

How to disable the Tv remote only right navigation focus using js-spatial-navigation on Webos?

"I am trying to implement https://github.com/luke-chang/js-spatial-navigation on the webos multiple lists if one list is finsihed after i click on the TV remote right navigation the foucs is going to next list but i want to stop the right focus on once user reaches the last item of the list but it should work on left and top and bottom focus"
I can't understand your problem either. From my experience the horizontal row is limited by the TV screen width and once you hit the last item in the row the right arrow keys doesn't work, but I'm not familiar with webos. I've had good success adding fading context text that appear when a item is focused and a changing hero graphic too. Check out http://loopzine.tv/firetv.htm
D-pad or keyboard with arrow keys required.

wxHaskell Button State

I'm writing an application using wxHaskell and I want to be able to detect the state of a button (whether or not it is pressed at any given time). I'm having a bit of trouble figuring out how to do this, however. First I thought that there might be a "button is pressed" attribute that I could use, but there didn't seem to be. Then I had the idea of maintaining an IORef which I update on button-up and button-down events. However, that would require that the Button object actually have button-up and button-down events, which is does not appear to. It is an instance of Commanding, but I assume that the command event is fired on button-up only, which isn't enough for that idea. Does anyone have any other suggestions?
Workaround
You can implement this yourself by detecting the low-level actions that trigger those events (eg. mouse button down, space bar down).
In WX you can use the following function and constructor:
mouse :: Reactive w => Event w (EventMouse -> IO ())
data EventMouse = ... | MouseLeftDown !Point !Modifiers
And, as you suggest, you could keep the state yourself in an IORef. My suspicion is that left button here means main button (right for left-handed users).
UI design principles
The second question, which you haven't asked by I'll answer, is whether this is good UI design.
The behaviour of a button (assuming interaction using a mouse) is that click events are reported when the user releases the mouse button in the button area after pressing the mouse button down in the same area. If the user moves away and releases, or presses 'Escape', there is no click.
Taking any action on a button being pressed (not clicked) would feel unnatural for users.
In practice, the only acceptable way to use this would be, imho, to take an action whose effects can only be witnessed after releasing and which is immediately undone if the click is cancelled (ie. mouse button released outside button area).
EDIT: Please, also, take into account that users with accessibility requirements may have OS settings enabled that affect how and when button clicks are reported (but not down/up mouse events).
There is no way to know if a wxButton is pressed or not because it is an abstraction of a push button which intentionally hides this implementation detail. If you need to know the button state, use a wxToggleButton instead.

Do I have the right idea with using SetCapture() for a windowless checkbox?

My Table control uses windowless checkboxes (because there can be an arbitrary number of checkboxes here). Right now, I use TrackMouseEvent(TME_LEAVE) and manually checking if the mouse is in the checkbox rect during a WM_LBUTTONUP. I have TODOs marked in my code for the edge cases that this causes, such as a missing WM_LBUTTONUP when the mouse has left the client area.
Now I notice today's The Old New Thing says buttons use mouse captures. This got me thinking, and after looking into it, mouse captures would fit what I need more appropriately; if my assumptions are correct it would handle the various edge cases I mentioned above and be more correct in general.
In particular, the assumptions I make are: I should abandon any capture-related operations on a WM_CAPTURECHANGED even if every other condition is met. I will get a WM_CAPTURECHANGED after a ReleaseCapture(). After a SetCapture(), I will always end with either a WM_LBUTTONUP or a WM_CAPTURECHANGED, whichever comes first.
I've read both MSDN and a few articles I've found by Googling "setcapture correct use"; I just want to make sure I've got the right idea and will be implementing this correctly. Do I?
on WM_LBUTTONDOWN
if the button is in a checkbox
SetCapture()
mark that we're in checkbox clicking mode
on WM_MOUSEMOVE
if we are in checkbox clicking mode
draw the checkbox in the pressed state
on WM_LBUTTONUP
if we are in checkbox clicking mode
leave checkbox clicking mode
THEN call ReleaseCapture(), so we can ignore its WM_CAPTURECHANGED
if the mouse was released in the same checkbox
toggle it
on WM_CAPTURECHANGED
if we are in checkbox clicking mode
abandon checkbox clicking mode and leave the checkbox untoggled, even if the mouse is hovering over the checkbox
Do I have the right idea here? And in particular, is my order of operations for WM_LBUTTONDOWN correct? Thanks.
What you have said is basically right, although a real checkbox tracks WM_MOUSEMOVE while in "clicking mode" and displays the checkbox in its original state if the mouse moves off of it. So to emulate that you should have:
on WM_MOUSEMOVE
if we are in checkbox clicking mode
if mouse is over the checkbox
draw the checkbox in the pressed (toggled) state
else
draw the checkbox in the original state

is there a trick to working with multiple visual studio panel objects at design time

Is there some sort of shortcut key that I am missing here for swapping panels around in the form editor of vs2010?
I have numerous panels which are swapped at runtime according to an enum "toggle" value and the only way I seem to be able to move them back and forth is to make one panel smaller than another and right click it. Half the time I end up selecting some other object in the action of trying to right my panels.
I figured there must be something i'm missing here.
there are icons on the layout toolbar for this task. I pick the panel in properties and move it around with those. Way easier than right clicking and hoping for the best.
edit: although sometimes the buttons are not enabled when you need them to be. Still right clicking a resize handle adorner dot will pop up the context menu where you can then choose to move back/forward.
I still wish there was some key combo I could press. Hitting the 4px of display area that the adorner dot occupies on my screen is sort of a dexterity test of sorts and slows me down.

Resources