By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

I need a toggle button so when a key is pressed it starts then stops when the key is

P: 1
I need this to start when PageUp is pressed then stop when PageUp is pressed again. or only start when PgUp is held down then when the key isn't pressed, it stops


static int uiStartCb(Ihandle *ih) {
char buf[MSG_BUFSIZE];
UNREFERENCED_PARAMETER(ih);
if (divertStart(IupGetAttribute(filterText, "VALUE"), buf) == 0) {
showStatus(buf);
return IUP_DEFAULT;
}

// successfully started
showStatus("Started filtering. Enable functionalities to take effect. L");
IupSetAttribute(filterText, "ACTIVE", "NO");
IupSetAttribute(filterButton, "TITLE", "Stop");
IupSetCallback(filterButton, "ACTION", uiStopCb);
IupSetAttribute(timer, "RUN", "YES");
}
return IUP_DEFAULT;
}

static int uiStopCb(Ihandle *ih) {
int ix;
UNREFERENCED_PARAMETER(ih);

// try stopping
IupSetAttribute(filterButton, "ACTIVE", "NO");
IupFlush(); // flush to show disabled state
divertStop();

IupSetAttribute(filterText, "ACTIVE", "YES");
IupSetAttribute(filterButton, "TITLE", "Start");
IupSetAttribute(filterButton, "ACTIVE", "YES");
IupSetCallback(filterButton, "ACTION", uiStartCb);

// stop timer and clean up icons
IupSetAttribute(timer, "RUN", "NO");
for (ix = 0; ix < MODULE_CNT; ++ix) {
modules[ix]->processTriggered = 0; // use = here since is threads already stopped
IupSetAttribute(modules[ix]->iconHandle, "IMAGE", "none_icon");
}
sendState = SEND_STATUS_NONE;
IupSetAttribute(stateIcon, "IMAGE", "none_icon");

showStatus("Stopped. To begin again, edit criteria and click Start.");
return IUP_DEFAULT;
}

static int uiToggleControls(Ihandle *ih, int state) {
Ihandle *controls = (Ihandle*)IupGetAttribute(ih, CONTROLS_HANDLE);
short *target = (short*)IupGetAttribute(ih, SYNCED_VALUE);
int controlsActive = IupGetInt(controls, "ACTIVE");
if (controlsActive && !state) {
IupSetAttribute(controls, "ACTIVE", "NO");
InterlockedExchange16(target, I2S(state));
} else if (!controlsActive && state) {
IupSetAttribute(controls, "ACTIVE", "YES");
InterlockedExchange16(target, I2S(state));
}
Apr 12 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.