I use PuTTY to connect to a shell (Unix Server). I can use the mouse to select Text from the CLI. Also, vim can also interact with the mouse, so I know that PuTTY does send mouse input to the server.
My problem is that I want to capture the mouse events in a C++ TUI , much like vim does (just, I will be handling them differently). I have gone through many sites, but none of them describes my problem precisely. I have a feeling that I will need xterm, but I don't know how to use it!
The best links that I found are :
How to read low level mouse click position in linux .
Weird insertion from Vim on mouse click --> How do I read this event?
A blessed UI for Jitsu --> Hats off to this guy!
Can anyone provide a sample code to read the mouse location? I can code the rest of the application then :)
It should work just fine to do this using the mouse-interface in ncurses (I'm sure that vim and other applications has no specific knowledge about how SSH/PuTTY communicates, it just picks up the mouse position as it would if it was a local connection - the sshd sorts out all the magic with translating network packets to keypresses and mouse-moves).
Here is a description of how you interface with a mouse in ncurses.
Related
I want to ditch Razer Synapse because it eats up to 600MB of RAM for nothing. I just want to use my macros for two additional keys found on my Razer Deathadder. I've sucessfully captured the HID packets for my Corsair K95 keyboard with C++ HID API and executed my macros, finally was able to say bye bye to iCUE. But I'm not able to open mouse as HID device. Everything should be configured properly, VID/PID, UsagePage and Usage too. But the interesting thing is that wireshark is able to capture the mouse, for me it doesn't for even when I try to open it with admin priveliges. Does somebody have any idea what I should do?
I've tried hidapitester application which is part of HIDAPI C++ library, it automatically closes the device and doesn't receive anything. If it's not possible to solve it in this way, which approach I should use to be able to capture the packets?
Thank you.
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 have a Symbol LS2208 barcode scanner and works OK in my linux box (Kubuntu 8.10 Intrepid Ibex). Whenever you scan a barcode the scanner (connected to an USB port) sends the reading to wherever the text caret is. I would like to redirect all the readings from the scanner to an specific widget in my application (i.e. a text edit control). How can I do it? Though I use C++ with Qt GUI library sample code is welcome in any language or GUI library.
That may be tricky in that most barcode scanners are also known as keyboard wedges. They function as a keyboard and shove keys into the event stream so as to be as indistinguishable from a keyboard as possible. This makes for the greatest compatibility.
Many USB barcode scanners publish themselves as a HID endpoint and then for all intents and purposes, they ARE keyboards.
There are a number of things you can try to do - many scanners are configurable to allow them to spew in a prefix and suffix around the barcode data. If you can test for that, you just send the string to the right place. This is unpalatable in that you have to metaprogram the scanner. Usually this is done with a special set of barcodes. Here is a link to the manual for your scanner. On page 249, there are barcodes for metaprogramming the prefix and suffix.
You might want to figure out how to be a client for the HID events and redirect the scanner events where you want them. I've never tried to do this on LINUX. It's a pain on both Windows and OS 9 era Mac (the last time I played with USB extensively).
I don't know the answer, but here are some suggestions to find out what your options are:
Install an event filter on QCoreApplication::instance() (or reimplement QCoreApplication::notify())
In event filter handler, output each event looking for anything useful:
void eventFilter(QObject *obj, QEvent *evt) {
qDebug() << obj << evt;
}
Examine the debug output to determine which events are triggered by the scanner.
qDebug() understands virtually every type and should give you reasonable output that will allow you to tell whether the it's coming in as keyboard events or something else.
It seems like there is a problem with the accepted answer. The input is going to be processed by whatever is considered to be the active application. Thus, if someone brings up a web browser and then starts scanning barcodes, the input goes to the web browser and not the application. The desired application won't even see the events.
If the application is active, then you can trap the events and eventually figure out which ones are coming from the barcode scanner. Then the appropriate widget can be activated to receive the input.
I have an iMac, and I want to be able to turn off the monitor when I go to sleep,. Alas, the iMac has no switch for this. I do not want to put the iMac into sleep mode, i want to write a "expose" like application or service, which when the mouse is put into the upper left hand corner of my screen, the display will sleep. Likewise, if i move the mouse away, it comes back.
Does anyone have experience with tracking mouse movements within the Windows and Display APIs I'd need to look up. I just need some direction to get started.
Cheers!
Chris
I've been asked to clarrify. Sorry if i'm confusing anyone. I'm running Windows Vista 32 via Bootcamp. I like that Mac OSX has a "hot corners" feature via Expose. I have noticed that besides power managment which runs on a time metric, there is no way to sleep the display at will in Vista.
I would like to write my own tool for this. I might be a glutton for punishment, but i'm a coder, and it's a good excuse to learn something new.
In Leopard, you can just go to "System Preferences" and "Desktop & Screensaver". Click the Screensaver tab, click "Hot Corners", selected the corner you want to change, then chose "Sleep display". Does that not work?
If it's an old CRT iMac then you can't switch off the screen without switching the computer off - the convection from the CRT is used to cool the processor!
Not really the answer you seem to be looking for, but cant you do this via the power save option and/or the screen saver - can it be set to nothing.
Can you not use the monitor power button?
Thanks for the clarification, Chris. I would reiterate:
just use a pre-existing solution like this: http://www.southbaypc.com/HotCorners/ (untested anything that does the same thing would work). If it allows you to run your pre-selected screensaver, then all you need to do is ...
... make an exe that does what you want (sleep the screen) and then rename it whatever.scr http://computer.howstuffworks.com/screensaver.htm/printable Do you have this working yet?
Once you get that working (and you can enjoy a Windows version of your desired OS X hot corners functionality) then worry about how hot corners are implemented. Your Win32 API question is still a good question but like you said you sound like you want to build it yourself. If that is the case, I would post a new question "Hot corners in Windows Win32 API Low level mouse tracking" or something to that effect and just ask: "how do these Hot Corners programs detect hot corner mouse-over events?" By the way my brother used the low level API to move the mouse cursor and simulate clicks so I know what you're asking is probably possible. It's just that your REAL question seems barried in all this discussion.