Get the current mouse coordinates - c++

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.

Related

Prevent other windows from "overriding" hotkeys with the windowsAPI

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.

Dim screen on Windows with C++

I've been looking into dimming a screen on a Windows platform from my program. I know that there's a SetMonitorBrightness API that allows this, but the issue for me is that it would be nice to be able to dim the screen on Windows XP as well (which that API does not support) and also dim screens on desktop computers.
So I did some research and found this utility that seems to dim my screen on a Windows XP desktop without a problem. I tried to contact the author to find out how they implemented the dimmer but I did not hear back from them.
So I was curious to hear from developers on this site, how do you think they managed to dim the screen when the SetMonitorBrightness API is not supported?
PS. I am a newbie developer myself trying to write an energy saving program for our small business. It is a nonprofit organization and we don't have funds to hire a Windows developer to do this for us. Most of our computers are Windows XP desktops, so as you can see I can't use SetMonitorBrightness API as it is widely documented on the web.
Thanks in advance.
In the case that you cite, have a look at the screensaver with Dependancy Walker. My guess is that they create a full screen window and use SetLayeredWindowAttributes() to set a semi-opaque setting for the window, thus making the screen appear dimmed. I doubt it would save you much money.
You might want to look into the DDC protocol which allows you to control aspects of some monitors. The MS API that allows you to do this can be found roundabout here: http://msdn.microsoft.com/en-us/library/windows/hardware/ff570290%28v=vs.85%29.aspx and you should look at the I2C functions too.
Alternatively you could look for a ready made library to do the DDC stuff for you, such as http://www.nicomsoft.com/products/i2c/. They too have a dimmer application that is free for personal use and non-free for commercial use. They may even allow you to use it for free if you contact them and explain it's for a non-profit organisation.
If you are trying to do this as an energy saving program why not use a screensaver setting that turns the monitor off after a certain period of idleness? In any case
Forgive me if this information is outdated, but I have done this in the past using SetDeviceGammaRamp. The 'Get' version is available too for state saving and restore. I have seen it used in C# programs through, so it might still be relevant albeit not too common anymore.

Programable way to determine the current double-tap speed setting in Windows 7

I'm implementing a touch interface for Windows in Win32 (C++). I would like to find out the current double-tap (not double-click) speed that Windows is set to. I know Windows is set to accept double-taps as various messages (depending on whether you're using gestures or not), but I'm looking at doing something a bit more advanced. I'm thus handling WM_TOUCH messages. I'm hoping there's a better (i.e. future-proof) way than rummaging through the registry to find that setting. MSDN wasn't helpful.
Since there doesn't seem to be a specific double-touch notification, I suspect the application is expected to decided for itself if a WM_TOUCH is part of a double tap. The most common way to do that is probably to check the timing between touches. By default, I'd imagine that most apps use the mouse double-click setting as the default.
GetDoubleClickTime

Controlling mouse in linux

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.

How can I code my own custom splash screen for Linux?

This is NOT a question on plain old boring customization; I actually want to create an program, you know, with source code, etc...
I'm thinking about programming my own media centre interface, and I figured it'd look better if I coded my own splash screen for when the OS is loading.
Note: The media centre interface will be run in X, but this question is regarding what will happen before the X server loads.
Simply, I'd like to make a splash screen application to hide the linux kernel boot messages. Is there a way I can program some animation in to this like some sort of animated progress bar for example? I assume that I won't be able to code any 2D/3D graphics (as that'd require X to be running, right?), so how would I go about generating that?
I'd prefer to do this in C++, but C is also an option.
Note: I'm not looking to use any existing "themes" or anything like that, just interested in the programming side of things.
Update:
Some suggestions have been to use standard images (.bmp, .jpeg, etc), I am not interested in loading images in to an existing application. But obviously I may want to load images in to the boot screen application that I will make.
I'm not tied to a Linux distro, so this can be for anything, although Debian or a Debian-based distro would be nice.
I like the suggestion about loading the X server early and running a loading screen from there, however is there not a more direct approach? Surely you can make a program which hides the boot messages and shows a custom program? Obviously this would be very low level programming, but that's what I'm looking for...
Also, I'm not interested in altering the boot loader (LILO, GRUB, etc).
Update 2:
So far good suggestions have been looking at the source code for applications like splashy and fbsplash. Can anyone better this suggestion?
For the graphical output you can use the Linux framebuffer, for application development you can use gtk which support rendering directly to the framebuffer GtkFB.
For the video and such you can use mplayer which also support rendering to the framebuffer.
For the initialization you have to look around the system used, debian uses a sysv init style initialization http://www.debian-administration.org/articles/212, ubuntu uses upstart.
I'd look into splashy source code. But you will need to code in C.
If you have the skills, you can implement a software based 3D engine (like in the good old days). A simple rotating cube shouldn't be very hard to code and there are tons of tutorials.
The downside is that you will increase the boot time, something not very pleasant in a media center.
Here's the thing: there is a library/kernel patch, fbsplash, that has already been written to do exactly what it sounds like you want to do. It will display an image in place of the normal boot messages, and it can also incorporate a progress bar. When you're trying to do something for which a well-established open-source implementation already exists, there's really no better way to learn how to do it yourself than to look at the source code.
Even if you're looking for something more complicated (say if you want to create some fancier animation than a progress bar), you might be able to start with fbsplash and modify it to suit your needs.
There are several ways you could do this. You could have the X server load very early, and just write a program to display the splash screen. You could also use the framebuffer device. If you are using Intel hardware, or are willing to use the OSS AMD drivers, or Nouveau for Nvidia, you could use kernel mode setting. For this, I would look at Fedora's Plymouth. You could just write a Plymouth plugin to display your splash screen.
The splash screen is simply an image (.bmp, .jpg, etc.) and can be loaded by the boot loader. Since you haven't specified the distribution you're using, look into LILO, grub, or whichever one is appropriate. Check the /boot directory for clues that will direct your search.
If all you want to do is have a nice clean boot sequence with your own splash and absolutely no boot messaging you can do the following:
First, silence grub, boot messaging, and console cursor:
GRUB_CMDLINE_LINUX_DEFAULT = quiet fastboot splash vt.cur_default=1 loglevel=0
GRUB_TIMEOUT = 0
This will very quickly and silently (fade to black) bring you to your login screen, where you can place a splash. Your distro may show it's own splash briefly, which you can change if you like.
This yeilds a professional clean boot sequence, without all the usual linux warts and wrinkles. (Like OSX and Windows).
I personally use Ubunutu with LXDE, and have a clean splashy boot in under 3 seconds, even on older hardware.