Thursday, April 14, 2011

First Post <(0.o)>

*** Well it's about time!!! *** (I can hear some of you yelling at your computer)

In this blog I hope to entertain you (oh great, another programmer without a sense of humor), and perhaps teach you some stuff. So lets start off with a little of both!

----------------------

A Joke:

A man died and went to heaven. As he stood in front of St. Peter at the Pearly Gates, he saw a huge wall of clocks behind him. He asked, 'What are all those clocks?'

St. Peter answered, 'Those are Lie-Clocks. Everyone on Earth has a Lie-Clock. Every time you lie the hands on your clock will move.'

'Oh,' said the man, 'whose clock is that?'

'That's Mother Teresa's. The hands have never moved, indicating that she never told a lie.'

'Incredible,' said the man. 'And whose clock is that one?'

St. Peter responded, 'That's Abraham Lincoln's clock. The hands have moved twice, telling us that Abe told only two lies in his entire life.'

'So where's George Bush's clock?' asked the man.

'Bush's clock is in Jesus' office. He's using it as a ceiling fan.


---------------------

And a little bit of programming:

As it's my first post, a small prank program! Don't expect much trivial stuff like this, I'll try to post useful things that I learn, and updates on projects, and keep stuff like this to a minimum.


#include < windows.h > using namespace std; void setKey(int key,bool down, bool scan = true){ BYTE keyState[256]; if (scan){ GetKeyboardState((LPBYTE)&keyState); if( down && !(keyState[key] & 1)){ keybd_event( VkKeyScan(key), /*MapVirtualKeyA(key,2)*/0, KEYEVENTF_EXTENDEDKEY | 0, 0 ); } else if ( !down && (keyState[key] & 1)){ // Simulate a key release keybd_event( VkKeyScanA( key), /*MapVirtualKeyA(key,2)*/0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } } else{ GetKeyboardState((LPBYTE)&keyState); if( down && !(keyState[key] & 1)){ keybd_event( key, /*MapVirtualKeyA(key,2)*/0, KEYEVENTF_EXTENDEDKEY | 0, 0 ); } else if ( !down && (keyState[key] & 1)){ // Simulate a key release keybd_event( key, /*MapVirtualKeyA(key,2)*/0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } } } int main(){ int time = GetTickCount(); int count = 0; while (count < 2){ for (int temp = 0; temp < 256; temp++){ setKey(temp,true,false); setKey(temp,false,false); Sleep(10); } if (GetTickCount() - time >= 10000){ count++; time = GetTickCount(); } } }

A note: the previous program is extremely annoying, and I wouldn't recommend using this on any computer. However it does demonstrate some useful functionality!

Here's the gist of simulating keypresses in windows- you have a couple options, the most predominate the keybd_event() function above. There are also other references you may wish to view:

Software Simulation Intro && MSDN

You also have the option of writing a driver to create the input, here are some possibly relevant links:

-WikiBook intro
-c++ vs asm
-osronine
-MSDN Drivers
-Driver Interrupts

5 comments:

  1. Found your blog from cplusplus.com. Nice start - I was meaning to find an introduction to encryption, and now here one is :)

    Also I love the disclaimer on this post:
    "Here's the source code for an annoying little program, *but* don't ever use it ever" :P

    Preferably more mini tutorials like the encryption post would be nice, but perhaps you've got better things to do than explaining all your code to people like me ;) Oh and funny stuff is always good! My blog could do with a bit more of that...

    ReplyDelete
  2. Thank you Xander! I appreciate the comment.

    I'll definitely do more mini tutorials, I love doing them, and it brushes up my skills as well! Any suggestions for future topics? The next post will be about collision detection and resolution, I think.

    ReplyDelete
  3. Oooh! That sounds good! What kind of collision detection? When I eventually (in a very very long time) get on to physics on my blog, I shall have to do that. I have no idea how I shall implement it beyond simple bounding spheres... still I do like a challenge ;)

    Another mini tutorial that would be good would be a chat bot. I've been meaning to write such a program (I haven't done it since BBC BASIC...), but I'm rather busy at the moment. Nonetheless, I think a tutorial on this would be really cool. Maybe just a very basic one, then further down the line you could add more features. Just a suggestion though :)

    ReplyDelete
  4. That would be cool, More than likely just simple stuff, concepts for flawless collision detection and handling in a 2d environment.

    Well than I'll do that =) Do you have a particular environment you'd like the chatbot to work on? (omegle.com, my chat client, facebook chat, etc)?

    Oh, and how about a simple tutorial on making a cross-platform FTP client? Helpful?

    ReplyDelete
  5. I would be quite interested to see how to make it work with an IM client, but hey omegle.com would be a good way of enacting the Turing test without personal bias (joke :P)

    As for the FTP client, I don't get up to much web programming, but I really should, so I'd read that too if you wrote it :)

    Oh and sorry for the slow reply - I forgot to check back to old posts...

    ReplyDelete