Hi,
I'll post my code here if someone wants to help. It's a bit simplified compared to the real code. I've borrowed some stuff from others on this forum. Thanks!
Code:
#include <windows.h>
#include <iostream>
using namespace std;
int MouseScroll(int roof) {
HANDLE hStdin,hStdout;
hStdin=GetStdHandle(STD_INPUT_HANDLE);
hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
DWORD num;
INPUT_RECORD inputrecord;
COORD location;
location.X=0;
location.Y=0;
int x_gammal = 0;
int i = 0; //What to do with counter int?
while (true) {
ReadConsoleInput(hStdin,&inputrecord,1,&num);
if (inputrecord.EventType == MOUSE_EVENT) {
SetConsoleCursorPosition(hStdout,location);
int x_ny = inputrecord.Event.MouseEvent.dwMousePosition.X;
if (x_gammal != x_ny) {
if (x_gammal < x_ny) {
if (i < roof) {
i++;
cout << i << flush; }
else {
i = roof+1;
cout << i << flush; }
}
else {
if (i > 0) {
i--;
cout << i << flush; }
else {
i = 0;
cout << i << flush; }
}
x_gammal = x_ny;
}
}
}
}
void MenuHandler(int choice) {
int x_gammal = 0;
int i = 0;
int menu_roof = 0;
long menu[] = {0,0,0};
//Menu choice
switch (choice) { //More cases will be added
case 1: //Focus mode
menu[0] = 2;
menu[1] = 6;
menu[2] = 3;
menu_roof = 2;
MouseScroll(menu_roof);
//SetPropFocusMode(0, menu[i]); //Used with other SDK
break;
}
}
int main() {
int menu_value = 0;
bool Continue = 1;
//camera control
//InitControl();
//GetPropCameraCount();
//Connect(0);
while(Continue) {
if (GetAsyncKeyState(VK_F1) < 0) {
menu_value = 1;
MenuHandler(menu_value);
}
}
//DisConnect(0);
return 0;
}
Every time the function MouseScroll is called i is set to zero. This stops it from changing its value. I would like MouseScroll to remember what value i had previously.
If everything then works as I expect the following will happen:
when F1 is held down I would be able to move the mouse in the x-direction and increase or decrease i.
I made it work when I wrote the code in one piece but not when splitting it into different functions.
Thanks very much for any help!
/Kristian