I'm writing a game in C++, and I'm trying to get it to recognize keyboard and mouse events. Google tells me that boost.signal is suitable for event handling, but none of the code samples or tutorials I've found tell me how to associate a keypress or mouseclick with a function. Can anyone shed any light on this?
I think taking a look at SDL and it's SDL input subsystem might give you some hints. It all depends on what is the source of your keyboard and mouse events. Is it SDL? DirectX? If neither, then you're probably doing it wrong :).
The events that you receive will depend on the operating system you're using, and any frameworks that stand between you and the OS. Qt is a popular cross-platform framework, for example.
If you're not using a GUI library or other type of engine that already provide you input informations, a good library to just get inputs is OIS : http://sourceforge.net/projects/wgois/
Related
This question was originally about how to trap mouse events, which i solved after a lot of research using SetWindowsHookEx with C++.
Problem is, its working for me on Windows, it works in applications, but it doesnt work in games.
can somebody help me understand why the mouse hook doesnt work in some games? could it be possible all the games i tried use Raw Input? :S
(i tried Ibb&Obb, Fallout 4, Metro Last Light and some other titles)
Basically im asking: how is it possible to use a Mouse Hook to trap it globally in all the applications running?
thanks for the helpers.
EDIT : I found out that most games i play use DirectInput. guess the better question is: How can i intercept mouse messages in DirectInput and prevent them from being registered by the game? i want to be able to drag the mouse and it would have no effect on the game.
after a lot of research i found out that, from what i understood, API Hooking (Microsoft Detours, API Hijack and more) is the only way to do it.
Important note: it doesnt help me much since API Hooking for games require DLL injection which will get you banned from Steam and other platforms.
I have an application that lives in the tray, and I need to detect the user activity so that I can perform certain tasks. For windows, I know that I can use GetAsyncKeyState or SetWindowsHookEx, but I would like to have a cross-platform solution.
Does anyone have a solution for this? maybe a reimplementation of keyPressEvent? Or would it be easier to just setup some macros and do it separately?
This is inherently platform specific.
I'd make sure to isolate whatever you do and separate the mechanism of capturing the event and recording the keystrokes from the consumption of those keystrokes. That way you only have to implement the capture/record mechanism on each platform and all of the other code should be pretty portable.
You may want to take a look at what SDL has done here. http://www.libsdl.org/
They have managed to abstract off all of that sort of thing, not just keyboards.
I am writing an application in C++ using CGL/OpenGL, and need keyboard/mouse input. I was trying to avoid Objective-C and Cocoa if possible. I am aware that one can capture input using Carbon, but seems that Carbon is slowly being phased out, plus it is not clear if it plays well with 64-bit applications. Does anybody know if there any other alternatives in OSX for mouse/keyboard input using C++ without going to something very low level (e.g. I/O kit)? Any code snippets to get me started?
Thank you-
Quartz event taps might do what you want. Without knowing why you are trying to avoid using the Cocoa event system it's hard to know what technology would be best for what you are trying to do.
Gaffer on Games wrote an article doing just what you want, context and surface creation with CGL and a minimal event loop (although it's a little out of date, for El Capitan you need CGLSetFullScreenOnDisplay())
http://gafferongames.com/2009/01/19/opengl-on-macosx/
It uses InstallApplicationEventHandler, one of the two keyboard APIs mentioned here:
Keyboard input on OSX
Basically I'm currently using the wiiuse library to get the wiimote working on linux. I want to now be able to control the mouse through the IR readings.
Can somebody point me in the right direction as to how to approach this? I know of uinput but there doesn't seem to be a lot of tutorials/guides on the web.
I'm working with c/c++ so a library in c/c++ would be helpful.
Cheers.
I think you should look into "becoming" a new mouse device. This would require developing a device driver that knows how to read the Wii device, and present that data to the input system as if it came from a mouse. The Linux kernel supports multiple mice connected at the same time, and merges the inputs from all of them, so this will work fine.
This book might be a handy help along the way. Not sure if it's possible to do this totally in userland, but that is of course worth investigating too.
I`m not sure if I understood you question corectly. If looking for controling mouse pointer from userspace look at XTest Extension Usefull link
Edit:
From kernel POV uinput looks like good starting point
In the end I decided to just draw "cursor" objects on the screen and use setup each input device to control a separate "cursor" object. This seemed the best idea as we were short on time.
I'm looking for a window... ugh... thing for OpenGL, I've been using SDL but more recently found that its not quite up to my needs in at least any code I've seen. I'd like to find some GUI library that allows me to develop using OpenGL (and SDL if at all possible) with a menu bar, possibly options at the side, and a working-out-of-the-box close button. Qt is the sort of thing I'm looking for, but I'd like to work with something that doesn't force me to make it open source.
A quick list of things I want, a working close button, ability to use OGL, cross platform, any licence that doesn't force me to become open source, free, and the ability to go full screen and change resolution on the fly.
I have searched myself, I'm not a lazy person really ;) I just want to get some opinions here before I dive off into anything and find its not really suitable for my needs.
Thanks in advance for any feedback.
Try wxWidgets. There's a link on using it with OpenGL here.
When Qt 4.5 comes out (later this month, I think) it will be LGPL, so if you can wait a couple weeks, you can use Qt without having to open-source your program.
GLUT (GL Utility Toolkit) comes close to what you're looking for. It's quick and easy and cross-platform, although it does not have support for menu bars. This page also has a number of GLUT-like alternatives.
For the out-of-the-box close-button enabled window, you can have GLUT, as mentionned before, and if your additional GUI needs are really simple, I think GLUT can provide you some.
You could also go for simple OpenGL rendered menus and buttons, either using NVidia Widgets or AntTweakBar.
You don't need 'support' for OGL as long as you can pass it the correct the information. On windows at least, if you have a windowing API that you can hook the HWND from, you can set up OGL to use pretty much any window you want. I've done this successfully with wxWidgets and straight win32. I can't help you with other platforms, but I suspect you can do something similar.
This works with D3D too and is a nice way of separating your rendering code from your windowing API.
SDL can create OpenGL Windows.
http://gpwiki.org/index.php/C:SDL_OGL
There are numerous rendered widget libraries such as those that rotoglup suggested. Have a peek at CEGUI and QuickGUI, they may make you happy (although CEGUI disappoints me with its abuse of XML). And here's a shameless plug: GLICT.