Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to make a scroll box with working buttons. I have the mouse click and the keyboard button to work to quit the program.

I have to make a scroll box with working buttons. I have the mouse click and the keyboard button to work to quit the program. I am having a problem getting the text to move faster and slower. The code is in C on a putty

void exit_scroll() { end_display(); exit(0); }

// this is the scroll delay. // It can be changed keys/mouse, so has to be global. int delay = 1000; int Box_mode = MODE_NORMAL; int Clock_expires = 0;

// keyboard and mouse handling void process_key(keybits KeyCode) { int row, col; if ( KeyCode & 0x80 ) { // mouse click row = (KeyCode & 0x70) >> 4; col = (KeyCode & 0x0f);

if (row == 0 && col == 4) { // "off" exit_scroll(); }

} else { // keyboard press switch (KeyCode) { case 'q': exit_scroll(); break; } } if (KeyCode & 0x30 ) { //mouse click row = (KeyCode & 0x40) >> 0 ; col = (KeyCode & 0x0b);

if (row == 0 && col == 0) { // "Fast" start_timer( delay/3); }

}else { //keyboard press switch (KeyCode) { case 'f': start_timer(delay/3); break;

} }

if (KeyCode & 0x50 ) { row = (KeyCode & 0x40) >> 1; col = (KeyCode & 0x0c);

if (row == 0 && col == 1) { // "Slow" start_timer( delay*3); }

} else { //keyboard press switch (KeyCode) { case 's' : start_timer(delay*3); break;

} }

void start_timer(int delay) { struct itimerval interval; // interval object struct sigaction new_action, old_action; // signal actions

/* See the manual entry for signal.h(3HEAD) for a list of all * signals. */

// blank out the signal mask sigemptyset( &new_action.sa_mask ); // clear flags (our application is pretty simple) new_action.sa_flags = 0; // set tick() as the signal handler when we get the timer signal. new_action.sa_handler = tick;

/* sigaction takes a pointer as an argument, so you have to * allocate space. The declaration of new_action() up above * has no star - that's the actual object, not just a pointer. */ if ( sigaction(SIGALRM, &new_action, &old_action) == -1 ) { perror("Could not set new handler for SIGALRM"); exit(1); }

/* set interval to the specified delay value. */ if (delay >= 1000) { interval.it_value.tv_sec = delay / 1000; // seconds interval.it_value.tv_usec = 0; interval.it_interval = interval.it_value; } else { interval.it_value.tv_sec = 0; interval.it_value.tv_usec = delay * 1000; // we need useconds interval.it_interval = interval.it_value; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago