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