Fastest way to capture what's on the screen in C - c

My goal is to write a program that would capture the screen in an efficient way.
Little twist, the screen will not be saved. My program will do various check on it (pixel's colors in some area.. etc).
The program will run in windows, and will need to take(and analyze) as many screenshot as possible per second, and will not be used in games. (That imply that I need the whole screen, like pressing prntscreen. It's not a problem if that fail in fullscreen game.)
All propositions are welcome, and I'd be glad to share any missing details.
Edit
As I wrote in the comment, capturing the screen for storing purpose is really common and easy to find.
I asked to be sure to not miss any method of capturing the screen without storing it at all.
The program will look the screen, take some decision then will quickly go to the next frame.

Perhaps look into SDL
A guick google returned this screenshot code for SDL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/2000-August/011387.html

Related

Processing and Kinect: Change speed of video according to distance from the sensor

I'm asking a question for a school project. I am trying to play a video in a loop and change its speed according to the distance from the Kinect 1414. When you are far the video plays at normal speed, which then increases as you get closer.
I tried in different ways but sometimes either the video doesn't loop or it doesn't show, I can only hear the audio. Other solutions don't let me change the speed of the video. Do you know any way to have the distance of a person affect the video?
Thanks.
Stack Overflow isn't designed for general "how do I do this" type questions like this. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense.
You need to break your problem down into smaller pieces and then take on those pieces one at a time. For example, can you start with a very basic sketch that just displays the distance from the Kinect? Don't worry about the video yet, just display the distance on the screen.
Separately from that, can you create another sketch that just shows a video playing in a loop? Work your way up from there: can you make it so its speed is based on a hard-coded value? How about on a value like mouseX?
Get those two basic sketches working perfectly by themselves before you start thinking about combining them. Then if you get stuck on one of those steps, you can post a MCVE along with a specific question (in a new question post), and we'll go from there. Good luck.

Corona / Lua / frustrating timer multiplication

I am in the process of building a mobile game with Corona SDK, which is based on Lua. Until now i didn't need any help but this time I can't seem to find the cause, and I've been searching for it for hours.
It's one of those timer problems, where, after leaving, removing, and revisiting the scene, items that are spawned within a loop just multiply themselves every relaunch. More specificly, everytime a "forbidden" collision happens, which leads to the relaunch, according to my onCollision function.
What I already corrected after hours of strenuous research :
--the code inside the onCollision function is now inside the "began" phase,
so that can't cause the multiplication
--the scene phases are also correctly used
--transitions and timers are all canceled right before the relaunch
Since the code would be too long for you to look through, I'd rather ask for some hints :
What do you have in mind can cause such problems, besides what I already mentioned.
I appreciate every answer! Thanks alot.
The above comments are valid, it is going to be hard to diagnose the problem without being able to look at the code.
In the past, I have found it very helpful to name all my objects when dealing with collisions, so when a collision happens I know what objects caused it and it is very helpful for debugging purposes.
It looks like you have an issue with how you are starting the scene and deallocating resources when the scene ends. You may want to start/stop physics when the scene leaves and comes back, but without code I can't give a concrete answer.

Radio buttons not selecting in old program

I wrote a large complex C program around 20(!) years go. As far as I can recall it worked fine at the time in all respects - it was probably running on windows 95.
Now I need to use it again. Unfortunately the radio buttons in it do not appear to work properly any more (the ordinary push buttons are all behaving correctly). As I click on the radio buttons, I get some feedback that windows is acknowledging my click in as much as I see a dotted line appear around the button's text and the circle of the button goes grey for as long as my finger is on the button, but when I take my finger off I see that the selected button has not changed.
My suspicion is that I was perhaps getting away with some bad practice at the time which worked with windows 95 but no longer works on newer versions of windows, but I'm struggling work out what I did wrong. Any ideas?
EDIT: Its difficult to extract the relevant code because the message handling in this program was a tangled nightmare. Many buttons were created programatically at runtime and there were different message loops working when the program was in different modes of operation. The program was a customisable environment for running certain types of experiment. It even had its own built-in interpreted language! So I'm not expecting an answer like "you should have a comma instead of a semicolon at line 47", but perhaps something more like "I observed similar symptoms once in my program and it turned out to be ..... " .. or perhaps "the fact that the dotted rectangle is appearing means that process AAA has happened, but maybe step BBB has gone wrong".
EDIT: I've managed to extract some key code which my contain an error...
char *process_messages_one_at_a_time()
{
MSG msg;
int temp;
temp = PeekMessage(&msg,winh,0,0,PM_NOREMOVE);
if (temp)
{
GetMessage (&msg, NULL, 0, 0);
if (msg.message == WM_LBUTTONUP)
{
mouse_just_released_somewhere = TRUE;
}
TranslateMessage (&msg);
DispatchMessage (&msg);
}
if (button_command_waiting)
{
button_command_waiting = FALSE;
return (button_command_string);
}
else
{
return (NULL);
}
}
There are two simple things to check when using radio buttons. First is to make sure that each has the BS_AUTORADIOBUTTON property set. The second is to make sure that the first button in the tab order and the next control after the set of buttons (typically a group box) have the WS_GROUP property set, while the other buttons have it clear.
A few suggestions:
I'd try to use spy++ to monitor the messages in that dialog box, particularly to and from the radiobutton controls. I wonder if you'll see a BM_SETCHECK that your program is sending (ie, somewhere you're unchecking the button programatically).
Any chance your code ever checks the Windows version number? I've been burned a few times with an == where I should have used a >= to ensure version checking compatibility.
Do you sub-class any controls? I don't remember, but it seems to me there were a few ways sub-classing could go wrong (and the effects weren't immediately noticeable until newer versions of Windows rolled in).
Owner-drawing the control? It's really easy to for the owner-draw to not work with newer Windows GUI styles.
Working with old code like that, the memories come back to me in bits and pieces, rather than a flood, so it usually takes some time before it dawns on me what I was doing back then.
If you just want to get the program running to use it, might I suggest "compatibility mode".
http://www.howtogeek.com/howto/windows-vista/using-windows-vista-compatibility-mode/
However, if you have a larger, expected useful life of the software, you might want to consider rewriting it. Rewriting it is not anywhere near the complexity or work of the initial write because of a few factors:
Developing the requirements of a program is a substantial part of the required work in making a software package (the requirements are already done)
A lot of the code is already written and only parts may need to be slightly refactored in order to be updated
New library components may be more stable alternatives to parts of the existing codebase
You'll learn how to write current applications with current library facilities
You'll have an opportunity to comment or just generally refactor and cleanup the code (thus making it more maintainable for the anticipated, extended life)
The codebase will be more maintainable/compatible going forward for additional changes in both requirements and operating systems (both because it's updated and because you've had the opportunity to re-understand the entire codebase)
Hope that helps...

What to program for a gadget that can deduce what I'm doing? The ultimate life-hack? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
This isn't really a programming question, more of an ideas question. Bear with me.
My sister gave me a well-used Nokia N95. I don't really need it, but I wanted it to do some programming for it. It supports a few languages, of which I can do Python.
My question is this: what to do with it? If I think about it, it has a lot to offer: i can program the GPS, motion sensor, wireless internet, sound and visual capture; it has a lot of hard disk space, it plays sound and video and so on.
The combinations seem limitless. The way I see it, it is a device that is easily always on me, has access to a huge data repository (the internet, and my personal data in it) and can be aware if I'm sitting at home, at work, or moving about somewhere. It could basically read my google calendar to check if I should be somewhere I'm not -- perhaps give me the bus schedule to get to where I should be. It could check if it's close to my home and therefore my home PC bluetooth/wifi. Maybe grab my recent work documents from my desktop computer, along with the latest Daily Show, for the bus journey to work. It could check my library account to see if any of my books are due, and remind me to take them with me in the morning. Set up an alarm clock based on what shift I have marked in my google calendar.
Basically I have a device that can analyze my movements in time (calendars with my data etc) and space (gps, carrier cell ids). By proxy, it could identify context situations -- I can store my local grocery store gps coordinates or cell mast ids and it could remind me to bring coffee.
Like I said, the possibilities seem limitless, and therefore baffling. Does anyone else have these pseudofantastical yearnings to program something like this? Or any similar ideas? How could this kind of device integrate into -- and help -- your life?
I'm hoping we could do some brainstorming.
"Gotta Leave" - A reminder that figures out the bus time, how far you are from a stop on your bus and shows a countdown till you "Could" leave (green), "Should" Leave (yellow), "Must" leave (orange), and "Gotta Run to get there" (red).
As inputs it needs what bus number you want to ride. You turn it on, it finds you, finds your closest few bus stops, estimates your walking speed at 2/mph and calculates when you need to leave where you are to get to the bus with 5 minutes waiting or less.
You should just pick any one and implement it.
It doesn't matter where you start, more that you actually do start. Don't concentrate on the destination, take a step and see what the journey holds.
Do it for a laugh to start and your expectation will be set right for both when you do find your killer app and when you don't.
"Phone home" - an interface to report home if you send a message to your phone that it is lost / stolen. Must be a silent operation from the phone holder's perspective
Options:
Self destruct mode to save your data from prying eyes
Keep calling with it's location every 10 minutes until an unlock is sent indicating the phone is found.
This is the same problem I face with the android (albeit java instead of python). The potential is paralyzing :)
I'd recommend checking out what libraries have already been written for doing cool stuff on that phone, and then building off of them- It's a system that provides inspiration, direction, and a good head start. For instance, on the android side, I'm fooling around with "zxing", a library that lets you read barcodes via the cellphone's camera. That's it's own sub-universe of possibilities, but at least it gives me a direction to go. "do cool things with information about products physically nearby"
"Late for Work" - Determines if you are not at work, buzzes you with a reminder and preps the phone to call into the sick line. Could be used if you are going to be late as well.
Inputs: Your sick line number. Time you should be at work. Where your home is, where your work is
Optional:
Send a text message
Post to an online in/out board
If you are still at home, sound an alarm
If you are still at home, call in sick, if you are not at home sent a "I'm going to be late" message
Comedy Option:
- If you don't respond to ten alarms, dial 911
To add on to what others have said, come up with some kind of office-GPS (via WiFi maybe? Does it have WiFi?) and tell you when you need to go to a meeting.

How to type faster [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I've typed around 75wpm for the last few years but I've always wondered how people type +100wpm.
I've searched but I primarily find typing tutors that teach you to type.. not teach you to type faster. So far the only tip I've come across is to learn dvorak.
Are there exercises or tips to help break through the 75wpm wall?
I'm assuming Steve Yegge's recent post prompted this? The comments contain a number of tools and games for measurement and improvement, both online and off. I'll list them here:
Gnu Typist
TyperA
TypeRacer (Several people named this site)
Typespeed
typeonline.co.uk
Update: I just tried GNU Typist as per Mark Biek's suggestion, and I have to say that it seems like the best of the lot mentioned so far. It looks like there is a Windows version available, although I'm sure there are prettier (and more expensive) apps out there.
Setting yourself up in an ergonomic typing position is a good start. Take a look at the diagram here - notice the arms in a straight line, feet on the floor, etc.
In my experience most people tend to slow down when they get to unusual keys - numbers, symbols, punctuation, etc, so maybe some focused practice on those key combinations? practice typing out long strings of numbers and symbols, maybe try to use some Perl code as your copy-page :)
One of the things that helped me was something I learned from pianist... when doing a touch typing program, deliberately slow down and speed up your rate of typing from disgustingly slow to really fast in slow waves. This helps train yourself to figure out how to get your fingers to work together faster and reinforces the key locations.
Another one is perhaps a speed reading course might help? Generally your fingers are the last line of slow down in typing.
If you want to practice while having a little fun check out http://typeracer.com
It let's you compete against other people and trust me, there's nothing better to get you typing faster than normal than a little healthy competition.
Practice!
GNU Typist is a great, free, multi-platform program for practicing. They have different sets of exercises for practicing touch-typing as well as general Speed Drills.
Like a previous poster said, practice, practice, practice. But, if you are a developer (since you are on this site I assume that you are), then writing code will probably not be the type of practice that you need to improve your typing skills past your current maximum. I would even argue that 75wpm is more than adequate for any code writing task. But if you really want to practice more then I would recommend picking up a copy of Typing of the Dead
Consider switching to a keyboard layout that's designed for quick typing instead of just being layed out as it is for historical reasons, e.g. Dvorak or Colemak.
For me, it also helped a lot to use the caps lock key as backspace, for example using SharpKeys on Windows.
If you are really hardcore, create your own keyboard layout. On Windows, you can do that with the Microsoft Keyboard Layout Creator.
Chat. A lot.
I never received any touch-typing training. Infact, when i first started, i had to search the keyboard for the key... Now after 7 years of IMing, its all muscle memory. I have never tried to speed my typing, but a lot of times it just flows without me even realizing that i am typing as i think. Also i have noticed i can type in my usernames and phrases i often use a LOT faster than the other things.
This may or may not have been a useful answer.
Be careful, increasing your typing speed can increase the risk of carpal tunnel syndrome:
"The typing speed may affect risk, in some cases, however. For example, the fingers of typists whose speed is 60 words per minute exert up to 25 tons of pressure each day." [source]
Consistency and practice. Four things that improved my typing dramatically:
Find a comfortable keyboard that
fits your hands very well. It's less
about ergonomics or split keyboards,
but more about finding one with perfect finger reach. And this means using the keyboard for a couple weeks to see if it fits. Once you pick a keyboard, use it 100% of time. Have the same keyboard at home and work.
Make sure your workstation is
properly fitted to you. Basically, follow any decent ergonomics guide (90 degrees everywhere is WRONG!!!).
All of this "ergonomics" stuff has the benefit of stress on the rest
of your body that can distract you or cause muscle fatigue (i.e. slower typing). Again, use the same workstation configuration everywhere--if that means getting the same expensive chair at home, do it.
When emailing, chatting, and posting, use complete words and sentences. Abbreviations, slang, and other "shortcuts" taught me a lot of bad typing habits and made me lazy. They also had a lot of awkward letter combinations that didn't show up in other places, including normal composition and coding.
Consistency. Use the same tools with
the same settings and shortcuts all
the time. The less time you spend
worrying about how the software
works and reaching for the mouse,
the faster your typing will be.
You need to pick yourself up a copy of Typing of the Dead and start killing zombies. You'll be honing your typing skills and preparing for the eminent zombie apocalypse at the same time! Grab the demo to check it out!
In all seriousness, I've had this game for years and it really has helped me improve my typing skills and it's way more fun than any other typing program out there.
Type to the beat of a song. Start with a slow beat and work your way up. Don't rush it. Typing in bursts is often counter productive. Rhythm causes accuracy. The keyboard is just like a musical instrument and that's how musicians gain accuracy. You also need to practice regularly, even if just for 5 mins each day, to train your muscles.
I forget the details, but I remember the following was asked of some famous violinist:
"How did you learn to play so fast?"
His reply: "Really, really slowly".
:)
Use both hands (and all ten fingers).
To maximize your typing speed, you need to use the opposite pinky to shift/ctrl etc. and you want to minimize the amount of time you have to "reacquire" the home position. My biggest increase in typing when coding was to really learn my IDE's keyboard shortcuts, since that eliminated the relatively slow process of using the mouse.
Disable your mouse. (This is more for overall computer productivity than WPM.)
And I know you can't do it on your own, so get someone to enforce it.
It'll force you to learn keyboard shortcuts and consider keyboard-friendly options.
A nice, tactile keyboard helps. Especially if it's blank. You'll be speeding along in no time.
http://store.daskeyboard.net/prdaskeulorb.html
If you are having a problem with a particular key combo or miss-typing a particular word, or even just want to practice something, put it into your password. That way you get it fixed in your muscle memory as you can't even see what you are typing.
Practice, Practice and Practice
Make it so that you cannot see the keyboard, this will force your mind to remember where the keys are. I used this when starting on the Colemak keyboard layout and it worked really well.
The biggest way I increased my speed was by never looking down at the keyboard. I also have a very ergonomic keyboard that splits the keyboard in half so I get use to the right hand using the right side and the left hand using the left side.
My hands aren't my bottleneck, so touchtyping doesn't make me any faster. I already don't get enough bitrate out of my head to max out my hunt and peck. some people (me) may never be able to TT effectively.
agreed on muscle memory though. common thngs like usr/pass always get boshed out quickly without thinking, but for code, my hands are not the bottleneck
Get a Kinesis Essential keyboard. Keys are laid out better for faster typing.
IRC-ing a lot helpen a great deal with me;
Especially playing those Trivia like games where the fastest one gets the points.
You can also try "typespeed" on Linux.
If you really need more speed and you think you've mastered the technique you can also consider using the Dvorak keyboard layout; It will help you type fast but you really need to adapt to it.
I switched to Dvorak and my typing speed has increased, and I also learned after 8 years, how to touch type.
I would double the suggestion(s) to switch to an ergonomic typing position. Also, I've noticed that I cannot type faster on my laptop. I have an external anti-RSI QWERTY keyboard (with the reverse-V style key layout), and I can type a lot faster with more accuracy on that that I can on my laptop.
If you use a contoured keyboard, like, for instance, the Kinesis Advantage keyboard, it is easier to type blind, since it is much easier to feel where your hands are on the keyboard if it isn't flat. After a couple of days I was typing considerably faster than on a normal keyboard. And there is also a version switchable to Dvorak layout, though I never bothered to try that.
About blind typing: in my experience, knowing where your hands are is the important and difficult thing in blind typing - and after years of keyboard use you know very well where the common keys are. So just concentrating every once in a while to have your hands in the proper position for blind typing, and to type the keys with the right finger will get you into blind typing in a couple of months without any additional exercise.
(source: kinesis-ergo.com)

Resources