سلام
یکی گفته براش یه برنامه بنویسم ولی من تا حالا از Arrow key ها استفاده نکردم ! خواهش می کنم کمک کنید کدهای اسکی شون را می خوام و ظاهرا با دستور getch() خونده نمیشن !
راهنماییم کنین لطفا
:41:
Printable View
سلام
یکی گفته براش یه برنامه بنویسم ولی من تا حالا از Arrow key ها استفاده نکردم ! خواهش می کنم کمک کنید کدهای اسکی شون را می خوام و ظاهرا با دستور getch() خونده نمیشن !
راهنماییم کنین لطفا
:41:
دوست عزیز اونطور کهمن میدونم باید این کلیدها رو دوبار بخونی تا بتونی کد اسکی اونا رو بدست بیاری
سلام این جوری:
کد:#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <process.h>
#include <ctype.h>
#define STRING_LENGTH 100
#define ARROW_KEY_NONE 0
#define ARROW_KEY_UP 1
#define ARROW_KEY_DOWN 2
#define ARROW_KEY_LEFT 3
#define ARROW_KEY_RIGHT 4
#define ARROW_KEY_POSSIBLE 5
// BEGINNING OF PROTOTYPES
void settext(void);
void getline(char * str2);
void showoutput(char * str2);
int checkarrowkey(char key);
// BEGINNING OF PROGRAM
int main()
{
char strexit[STRING_LENGTH];
char strquit[STRING_LENGTH];
char holdtextline[STRING_LENGTH];
system("cls");
holdtextline[0] = '\0';
getline(holdtextline);
showoutput(holdtextline);
printf("\n");
return 0;
}
// END OF PROGRAM
// BEGINNING OF FUNCTIONS
void settext(void)
{
char text;
text = getch(); // holds the output on screen
}
void getline(char * str2)
{
char str1[STRING_LENGTH];
int num = 0;
int checkkey = 0; // used to check for special keys
printf("Enter your text:"); // instructs you to enter something
do // starts loop for input
{
if (num == STRING_LENGTH)
{
break; // exits when the string fills up
}
else
{
str1[num] = getch(); // puts a char into 'str'
}
if ((str1[num] == '\b') && (num <= 0)) // starts the backspace handler
{ // if you're at the beginning...
// do nothing
}
else // but if everything's alright...
{
/////////////////////////////////////////////////////////////////
// This is where I check to see if the user typed an arrow
/////////////////////////////////////////////////////////////////
if((str1[num] == '\0') && (num >= 0))
{
num++;
goto last;
}
else
{
if((num > 0) && (str1[num - 1] == '\0') && (str1[num] != '\0'))
{
checkkey = checkarrowkey(str1[num]);
switch(checkkey)
{
case ARROW_KEY_UP:
printf("\nYou pressed the UP arrow key!");
return;
case ARROW_KEY_DOWN:
printf("\nYou pressed the DOWN arrow key!");
return;
case ARROW_KEY_LEFT:
printf("\nYou pressed the LEFT arrow key!");
return;
case ARROW_KEY_RIGHT:
printf("\nYou pressed the RIGHT arrow key!");
return;
default:
return;
}
}
}
/////////////////////////////////////////////////////////////////
// This ends where I check to see if the user typed an arrow
/////////////////////////////////////////////////////////////////
printf("%c", str1[num]); // echoes your char to the screen
}
str1[num] = tolower(str1[num]); // converts it to lowercase
if ((str1[num] == '\b') && (num >= 1)) // removes the last-typed char
{ // from the screen and from the
printf(" \b"); // string
str1[num - 1] = '\0'; //
num = num - 1; //
}
else
{
if (str1[num] != '\b') // if everything is alright...
{ //
num++; // it increments 'num' by 1
}
}
last:
} while(str1[num-1] != 0x0D); // loops until ENTER is hit
str1[num - 1] = '\0'; // create the NULL string char
strcpy(str2, str1); // copy 'str1' to 'str2'
}
void showoutput(char * str2) // beginning of 'showoutput'
{
int length = strlen(str2); // sets 'length' to the length of
// the string 'str2'
printf("\n\nYour text was '%s' ", str2); // outputs 'str2' to screen
printf("\n'%s' is %d characters long",// outputs 'str2' and its
str2, length); // length to the screen
}
int checkarrowkey(char key)
{
int whichkey = 0;
char str1 = '\0';
//char str2[STRING_LENGTH];
str1 = key;
switch(str1)
{
case 'H':
whichkey = ARROW_KEY_UP;
return whichkey;
case 'P':
whichkey = ARROW_KEY_DOWN;
return whichkey;
case 'K':
whichkey = ARROW_KEY_LEFT;
return whichkey;
case 'M':
whichkey = ARROW_KEY_RIGHT;
return whichkey;
default:
return 0;
}
}
سلام
ميشه يكي بگه كه اصلا Arrow key چي هست؟
منظور از arrow key کلیدهای جهت نما هستند...نقل قول:
بالا پائین چپ راست....:20: