I've run across some information across the net using the mouse in a C++ console, but I am still new to the language and confused.
I am using the Dev C++ compiler on Windows 7 and want to use the mouse to click and capture an input from the console screen, is this possible with the standard libraries? How would I use the mouse to cin?
What's preventing you from using Win32? It will be much easier to use the mouse here since all you need to do is handle messages. More information on what you're trying to achieve might help us in finding you the best solution.
By the way, Dev C++ last I saw is very old and I believe no longer maintained. Eclipse is better (even it if is sometimes intolerable). You can also use Visual Studio 2010/2012 Express editions.
This is not possible with standard C++ input/output.
You need to use Win32 Console API and enable ENABLE_MOUSE_INPUT Low-Level Console Mode.
Then you will be able to read mouse events using ReadConsoleInput() or PeekConsoleInput() Win32 API functions.
See MSDN example on reading console input events.
Please note that mouse cursor position is provided in terms of the console screen buffer's character-cell coordinates, not pixel-wise coordinates.
Related
I am writing an C++ Application and have to read if an arrow key is pressed or not.
I only found some function that are only working on Windows.
You have such problem because you just ask the wrong question. If you application is a command line tool and is accessible from a terminal, than it's just impossible to know which keys are pressed at the moment because the terminal can be far away from the machine where your application runs and which is more important, there is no reason for terminal to send you the arrow key presses because terminal can use them for text navigation.
So you may search how to make the terminal to send you key presses. Not every terminal will support it, but, I think, most of modern terminals in modern OS do.
If you has a gui application that is for running locally and assuming that you control it from the keyboard that is plugged in. Than you should search for the documentation for your gui toolkit. (Qt, wxWidgets, raw xorg, windows API, etc.)
So there are just no native C++ solution for this problem because you question just has no sense in many situations.
So you can use some console library like ncurses or gui toolkit like Qt or search for a native solution in your particular situation, but don't expect this last way will work without any additional code on other machines.
Or just search for other libraries that can allow you to do it.
As you say you only found material for Windows, I assume you are looking for a Linux-Unix way. Old dinosaurs like me remember the time when we only had true consoles (only a keyboard and a 80x25 display). And in these early times existed low-level libraries to interpret keypad transmitted keys and position cursor on screen on almost any terminal, and higher level ones to use the screen as a (text only) GUI.
You should look for curses or ncurses for high level libraries, and terminfo for the low-level capabilities.
I'm trying to learn the basics of the windows API by making a program that, when the PRINTSCREEN button is pressed, will save a .jpeg and instantly upload it to imgur. Currently, while I'm playing most games or just browsing the desktop, this program works fine.
Some games, however, seem to block my ability to use this hotkey. (Dark Souls 2 specifically does this.) I currently use
RegisterHotKey(NULL, 1, 0, VK_SNAPSHOT)
to assign the button to my program. However, when some games are running, neither the above RegisterHotKey nor the below GetAsyncKeyState work when the key is pressed.
GetAsyncKeyState(VK_SNAPSHOT)
(I don't want to use GetAsyncKeyState due to the fact that it will keep bugging the windows API and make the program unnecessarily slow, it was just for test.)
Does anyone know of a way to stop this from happening?
(and, on an unrelated note: If it is a simple task, how would I take a screenshot spanning multiple monitor(s)? Mine currently works on only my primary monitor...)
If the application is using raw input for its keyboard mapping, then the keyboard processing code bypasses the hotkey checker. I personally have no idea if Dark Souls does this or not, but I am familiar with the Windows kernel code that does keyboard processing.
I want to know how I can receive the event of a middle mouse clicked in C++. Is there anyway to do so? If there is, how exactly can I implement this? I've read online that I can use WM_MBUTTONDOWN however I am really unfamiliar with using this and I've been told that it is indeed not even part of C++.
WM_MBUTTONDOWN is defined as part of the Windows API. It is just an integer value that's recognized by the operating system. You can use C++ to compile a Windows application, although the language doesn't matter in this case.
A typical Windows application has a message loop. When a message is received by your application, you can decide what to do with it before passing it back for the next application to handle.
I recommend reading the Forger's Guide.
There is osgGA::GUIEventAdapter in OpenSceneGraph that could detect mouse events. However, I want the program to detect two mice on the same computer and the program can only treat two mice as one. I know there is a Windows MultiPoint Mouse SDK, but I think it is used in WPF with C#, not sure if it could be used in C++
Also, there is a GlovePie, but it is not open source and not sure how to use that in vs2010.
VRPN may be a good choice, but do not know exactly how to implement two mice. Get the dll files of two mice and extract functions by vrpn?
Take a look at "Raw Input" (http://msdn.microsoft.com/en-us/library/windows/desktop/ms645543(v=vs.85).aspx)
From that page:
An application can distinguish the source of the input even if it is from the same type of device. For example, two mouse devices.
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/