Errors in my c++ code

closed account (EvCSLyTq)
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
This part does not make sense.
 
char far *ch=(char far*)0x417;


This would be the closest thing I can make out of it that makes sense.
 
char far = (char) 0x417;


And your while loop is kind of wacky.

What is your code supposed to do exactly?
Last edited on
closed account (EvCSLyTq)
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:-
Last edited on
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.
Last edited on
closed account (EvCSLyTq)
Any idea how to do it different?
To get key inputs for virtual keys (ctrl, alt, del) you need to have WinAPI (for windows) or the equivalent for other platforms.

Something simpler.
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
int main()
{
    cout<<"Press Enter to exit \n";
    cin.ignore();
    return 0;
}


Would just need you to press Enter to exit.
closed account (EvCSLyTq)
Yes. But i want to make a program to reprogram my keyboard (for example: when i press g, it would type f).
Why would you need a program to do that exactly?
It sounds like a key-scrambler.
Yes. But i want to make a program to reprogram my keyboard (for example: when i press g, it would type f).


For that kind of functionality, you'd need WinAPI's to get a handle to the keyboard

 
HANDLE Keyboard = GetStdHandle(STD_INPUT_HANDLE);


Then check for keypress events

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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.
Last edited on
Topic archived. No new replies allowed.