When I write this code into my c++ compiler (dev c++) it gives me errors:
expected primary-expression before "char"
expected `;' before "char"
`ch' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
error: expected `)' before "break"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include<stdio.h>
#include<conio.h>
int main()
{
char far *ch=(char far*)0x417;
printf("Press CTRL+ALT+LeftSHIFT to exit");
while(1)
{
if((*ch&2)&&(*ch&4)&&(*ch&8)
break;
}
return 0;
}
I don't know what to do and what is even wrong.
Please help.
drobilc
The program should close when i press ctrl+alt+shift.
HERE IS THE TEXT FROM THE WEBPAGE:
The bits of the byte 0x417 keep track of the status of the keys whereas the bits of the byte 0x418 only monitor whether the keys are pressed or not.
Now that we know how the keyboard stores information in memory, we can make our own keyboard shortcuts. We want to make a shortcut CTRL+ALT+SHIFT. This shortcut does not exist. We will write a program where, CTRL+ALT+LeftSHIFT will be used to quit the program. In the program, we will continuously monitor the address 0x417 and will see when the bits 1,2,3 are set(i.e. become 1) all at once. Below is the program:-
Reading from various sources, this leads me to believe that this code is for an older, different standard and I don't think your code lends to the current standards.
Since I remember DevC++ uses GCC, I think your tutorial does not apply to your compiler.
int GetKeyInternal()
{
DWORD Key;
INPUT_RECORD IsPressed;
//Get the console input
ReadConsoleInput(Keyboard, &IsPressed, 1, &Key);
if(IsPressed.EventType == KEY_EVENT)
{
if(IsPressed.Event.KeyEvent.bKeyDown)
{
return IsPressed.Event.KeyEvent.wVirtualKeyCode;
}
}
return 0;
}
int GetKey()
{
int i = 0;
while(i == 0)
{
i = GetKeyInternal();
}
return i;
}
Then integrate it to a switch() which will call the appropriate display output.
It's up to you how you'll implement it to your program though, since I'm not too familiar with WinAPI myself.