Unbind Key Presses - browser

I'm making a game that involves, like all games, key presses. Only left and right arrow and the Space Bar. They work, but the browser is pre-set to scroll left, right, or jump down on those keys. Is there any way to unbind those keys in the code? Thanks.

you should be able to prevent the default browser behavior by returning false after the key is pressed. However depending on how you are intercepting the key events it seems to work different on different browsers and even for different types of keys (alpha vs 'command' keys)
jquery preventDefault and stopPropagation might also work,
the comments at the bottom of this documentation give alot of good hints
http://api.jquery.com/event.preventDefault/
based on the info there I put this small bit of code together, seems to stop the space bar and down / up arrows from moving the scrollbar in both opera and firefox
try this code (jquery needed) in firefox with firebug console enabled
$(document).bind('keydown, keypress', function(event) {
console.debug(event.keyCode + " - " + event.which);
// event.preventDefault();
return false;
});

Related

How do I write directly to the screen?

Specifically, I want to display text and images on the monitor, on top of all other windows, but without being clickable or in any way possible to interact with - clicks on it should go straight through to whatever window is underneath.
So far, my research has led me to try and read the X documentation regarding the composite overlay window, but unfortunately I have not been able to get anywhere with it. The only resource I found that was of any help is a small nodejs library (node-x11) which unfortunately appears to have been abandoned while still incomplete, and which I was not able to get to work. Apparently there is also a python library, but that seemed to be even less complete than the nodejs on.
node-x11 author here (and it's not abandoned, I just only add functionality I need or users request, so if you missing something please fill an issue!)
You can use GetOverlayWindow from composite extension:
Version 0.3 of the protocol adds the Composite Overlay Window, which
provides compositing managers with a surface on which to draw without
interference. This window is always above normal windows and is always
below the screen saver window. It is an InputOutput window whose width
and height are the screen dimensions. Its visual is the root visual
and its border width is zero. Attempts to redirect it using the
composite extension are ignored. This window does not appear in the
reply of the QueryTree request. It is also an override redirect window.
These last two features make it invisible to window managers and other X11
clients. The only way to access the XID of this window is via the
CompositeGetOverlayWindow request. Initially, the Composite Overlay
Window is unmapped.
CompositeGetOverlayWindow returns the XID of the Composite Overlay
Window. If the window has not yet been mapped, it is mapped by this
request. When all clients who have called this request have terminated
their X11 connections the window is unmapped.
Composite managers may render directly to the Composite Overlay
Window, or they may reparent other windows to be children of this
window and render to these. Multiple clients may render to the
Composite Overlay Window, create child windows of it, reshape it, and
redefine its input region, but the specific arbitration rules followed
by these clients is not defined by this specification; these policies
should be defined by the clients themselves.
node-x11 example:
var x11 = require('x11');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('composite', function(err, Composite) {
Composite.GetOverlayWindow(root, function(err, overlayId) {
// now you can draw on overlayId window here.
});
});
});

How can I create an X window/client that is on top of all other windows, not under WM control and has no input? (overlay, OSD)

I want to write applications (or use existing ones, that would be even more convenient) that behave like a hardware screens OSD (on screen display), only without input.
That is: A graphical output (e.g. from a GUI toolkit like Qt or Gtk) is placed on a layer where it is above even fullscreen-windows like Firefox F11 mode or a video player in fullscreen mode. That includes "above" the mouse cursor as well, so technically and graphically the mouse cursor would move below this widget.
I don't know about real fullscreen applications with SDL or OpenGL though, but this is not the requirement. If you know this as well please include it in your answer.
Real world applications are read-only overlays like a little webcam window, a TV-station like logo or premade annotations. So all in all this is meant for live presentations, streaming and recording of screencasts and tutorials with minimal post processing.
My own hacked, unsuccesful, experiments showed at least that removing this window from the WM control ( I did this by choosing a GTK popup dialog instead of a real main window) lets you position in absolute coordinates and it will ignore things like virtual desktops and workspaces, which is good, so you can switch between those and the overlay/HUD will stay in place.
Of course this cannot be done in software with the same Z-value (top/bottom windows) as the hardware screen. So technically I am talking above all other windows but below the screensaver or lock-screen layer.
+1 internet for linking to docs and giving the right keywords.
+2 internet for a working code example, language, gui-toolkit etc. doesn't matter.
You probably need composite overlay window from Composite extension - see section 3.2 "Composite Overlay Window" extension docs. (cursor is above this window)
Version 0.3 of the protocol adds the Composite Overlay Window, which
provides compositing managers with a surface on which to draw without
interference. This window is always above normal windows and is always
below the screen saver window. It is an InputOutput window whose width
and height are the screen dimensions. Its visual is the root visual
and its border width is zero. Attempts to redirect it using the
composite extension are ignored. This window does not appear in the
reply of the QueryTree request. It is also an override redirect
window. These last two features make it invisible to window managers
and other X11 clients. The only way to access the XID of this window
is via the CompositeGetOverlayWindow request. Initially, the Composite
Overlay Window is unmapped.
Example using node-x11:
var x11 = require('x11');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('composite', function(err, Composite) {
Composite.GetOverlayWindow(root, function(err, overlay) {
// already automatically mapped here:
//
// CompositeGetOverlayWindow returns the XID of the Composite Overlay
// Window. If the window has not yet been mapped, it is mapped by this
// request. When all clients who have called this request have terminated
// their X11 connections the window is unmapped.
});
});
});

Howto prevent a CFrameWnd from being mouse moved

I have an application that displays a CFrameWnd that is displayed on top of the main window. I need the window to be non-movable and non-resizable when the user selects a certain mode for the window.
My CFrameWnd is created with the styles WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_POPUP
I have come across a solution using an overload of CWndOnNcHitTest to rewrite
HTLEFT,HTRIGHT,HTTOP,HTTOPLEFT,HTTOPRIGHT,HTBOTTOM,HTBOTTOMLEFT,HTBOTTOMRIGHT,HTSIZE,HTCAPTIONto HTBORDERto prevent the framework to recognize the areas responsible for sizing / moving.
This method works well for resizing in my case, but moving the window is still possible, although the hittest override works correctly (verified with traces).
Is there anything wrong in my approach, or could there be something interfering with this solution and if so, do you have any tips on where to look?
You should be able to make OnNcHitTest() work, don't return HTCAPTION.
Still, there's more than one way to move/size a window, you also have to worry about the system menu (type Alt+Space). Write a message handler for WM_MOVING and WM_SIZING and override the RECT so the window stays put.

MonoTouch Dismiss Keyboard (sort of)

I am writing a MonoTouch iOS app. I have read many postings about ResignFirstResponder and I am using that.
My app is a typical table view app. I have done my own custom table cell view. The UITextField controls that cause the numeric keypad to come up in the first place are all on the custom table cell.
Currently I have it so that if you tap on the background of the cell I call ResignFirstResponder on all the text fields. This seems to work, but is not intuitive. I had a new beta tester get it last night and he tapped on one of the text fields and the keypad came up and he was lost as to how to get rid of it. After I told him to just tap the background, he now is fine, but obviously I want a solution that is obvious and doesn't require me to tell everyone how it works.
I read one post about a way to add a DONE button to the keypad, but it looked like a total hack and even broke when 3.2.1 came out and I don't want to have to worry about my app breaking when a new OS comes out.
Suggestions?
I would keep the background click->ResignFirstResponder that you have already, but add to it.
Curious, what button do you have set in the bottom right of the keyboard? There are options to show a Done, Search, Go, Next etc. buttons that can be setup to ResignFirstResponder. Pick the button that makes sense in your situation.
You can hook into the bottom right button by setting a callback to UITextField.ShouldReturn and calling ResignFirstResponder. You can just return false (that return value is for allowing line breaks in your UITextField).
Found an example here of hooking up ShouldReturn.

Problems with refreshing a draggable MFC window

Greetings.
I have to make a draggable MFC dialog window, which has a background - used that: http://www.codeproject.com/KB/graphics/picturewindow.aspx - and has several picturebox controls. I have tried two approaches, and while they do work, they have some problems.
First approach is "Manual" - on the LBUTTONDOWN message I check if it;s on a clean area of my window, and set a flag variable. On MOUSEMOVE, the flag is checked and if it's set, a MoveWindow function is called, and then, Invalidate(1). On LBUTTONUP, flag is unset.
This approach works correctly and redraws as needed, but is somehow very slow - if I'm moving the cursor too fast, the window falls behing and isn't dragged, as cursor's not over the window anymore.
The second approach is "Automatic" - I just call
DefWindowProc(WM_SYSCOMMAND, SC_MOVE+2,MAKELPARAM(point.x,point.y));
on LBUTTONDOWN, and it handles the rest, it's quick and never fall behind, but when I drag it over screen's edge ( so that some part of the window gets invisible), when I drag it back, all the controls get invisible and are not refreshed, background is okay. I suppose that's because Invalidate() isn't called during movement that way, as I actually call it after calling DefWindowProc() and so, everything is refreshed properly when I depress the button.
What should I do to improve either of those solutions? I need it both fast and correct. I may have not provided some required information, I'll add it is need arise.
Thanks in advance.
Solved the problem, by modifying the second way. I added a total redraw to the OnPaint(), and to get rid of flicker, I only redraw durng dragging, by using a flag variable.

Resources