Using the keypad numbers

Posted By: robertbruce

Using the keypad numbers - 05/27/09 14:01

Hello,

I have developed a small project where the player has to guess a number from 1-9.

I can enter the code using the keyboard numbers from 1 to 9 but nothing happens when pressing the numerical keypad numbers.

I have the num_lock on. Why does this not work?


I am using key_pressed and the scan code as below
///////////////////////////////////////////////////////////////////////
var answer;
var correct_answer;
answer = int(random(9)) + 1; //choose number 1-9
correct_answer=answer+1;//this is for the corresponding scancode

var guesses=3;


action check_key
{
while(guesses>0)
{
if(key_pressed(correct_answer))
{
//access granted
//trigger door open
}
else
{
//buzzer
//reduce guesses by 1
}
wait(1);
}
}
///////////////////////////////////////////////////////////////////////



Does the keypad not work as the keypad values are

1 = end
2 = cursor down
3 = page down
4 = cursor legt
5 = null
6 = cursor right
7 = home
8 = cursor up
9 = page up


would appreciate an explanation

thanks,

Rob

Posted By: Anonymous

Re: Using the keypad numbers - 05/28/09 06:12

Try this small proggy to check the scancodes of the keys:

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

var	gv_key;

PANEL* 	pan_info = {	
	digits 10, 20, "Keycode last pressed: %3.0f", *, 1, gv_key;
	flags = VISIBLE;	
}

void main(){	
	
	// loop till infinity (or ESC was pressed)
	while(1){
		gv_key=key_lastpressed;
		
		switch(key_lastpressed){
			case 71: 	beep(); 
					break;
			case 72: 	beep(); 
					break;			
			// ...
		}
		
		wait(1);
	}
	
}

Posted By: Anonymous

Re: Using the keypad numbers - 06/04/09 06:10

Try this demo:

Code:
// author: u.seifffert / gameus!de
// date:   06.2009
// 3DGS, lite-c 7.7x
// open source
///////////////////////////////
#include <acknex.h>
#include <windows.h>
#include <default.c>
///////////////////////////////

// shows the keystate of the numberkeys and the numpad keys (if numlock is activated)
// VK_NUMPAD0, VK_NUMPAD1, ... you find declared in windows.h


var gv_keystate[10];

PANEL* pan_info = {
	digits = 20,20,"Press the number keys or the keys from the numpad (while numlock is active)", *, 0, 0;
	digits = 20,40,"key 0 %3.0f", *, 1, gv_keystate[0];	
	digits = 20,50,"key 1 %3.0f", *, 1, gv_keystate[1];
	digits = 20,60,"key 2 %3.0f", *, 1, gv_keystate[2];
	digits = 20,70,"key 3 %3.0f", *, 1, gv_keystate[3];
	digits = 20,80,"key 4 %3.0f", *, 1, gv_keystate[4];
	digits = 20,90,"key 5 %3.0f", *, 1, gv_keystate[5];
	digits = 20,100,"key 6 %3.0f", *, 1, gv_keystate[6];
	digits = 20,110,"key 7 %3.0f", *, 1, gv_keystate[7];
	digits = 20,120,"key 8 %3.0f", *, 1, gv_keystate[8];
	digits = 20,130,"key 9 %3.0f", *, 1, gv_keystate[9];
	flags=VISIBLE;
}

void main(){
	while(1){
		gv_keystate[0]=(abs(GetKeyState(VK_NUMPAD0))>1 || key_0); 
		gv_keystate[1]=(abs(GetKeyState(VK_NUMPAD1))>1 || key_1); 
		gv_keystate[2]=(abs(GetKeyState(VK_NUMPAD2))>1 || key_2); 
		gv_keystate[3]=(abs(GetKeyState(VK_NUMPAD3))>1 || key_3); 
		gv_keystate[4]=(abs(GetKeyState(VK_NUMPAD4))>1 || key_4); 
		gv_keystate[5]=(abs(GetKeyState(VK_NUMPAD5))>1 || key_5); 
		gv_keystate[6]=(abs(GetKeyState(VK_NUMPAD6))>1 || key_6); 
		gv_keystate[7]=(abs(GetKeyState(VK_NUMPAD7))>1 || key_7); 
		gv_keystate[8]=(abs(GetKeyState(VK_NUMPAD8))>1 || key_8); 
		gv_keystate[9]=(abs(GetKeyState(VK_NUMPAD9))>1 || key_9); 
		wait(1);
	}
	
}



Posted By: DLively

Re: Using the keypad numbers - 04/19/15 21:10

Thank you laugh
© 2024 lite-C Forums