Simple (mock) Keyboard Layout with C\C++ : The following , is a simple keyboard layout , created , using the BGI graphics library of Turbo C/C++ 3.0 :
While running this program , make sure using correct path for BGI graphics driver .For example : if Turbo C/C++ is installed in the following location "C:\TC" , then the BGI graphics path should be "C:\\TC\\BGI" :
Screenshot :
C++ Code :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
int u,v;
int gdriver=0,gmode=0;
void cursor_on(void)
{
union REGS r;
r.x.ax=0;
int86(0X33,&r,&r);
}
void cursor_off(void)
{
union REGS r;
r.x.ax=2;
int86(0X33,&r,&r);
}
int leftb_pressed(void)
{
union REGS r;
r.x.ax=3;
int86(0X33,&r,&r);
return(r.x.bx&1);
}
int rightb_pressed(void)
{
union REGS r;
r.x.ax=3;
int86(0X33,&r,&r);
return(r.x.bx&2);
}
void mouse_position(int *x,int *y)
{
union REGS r;
r.x.ax=3;
int86(0X33,&r,&r);
*x=r.x.cx;
*y=r.x.dx;
}
music(int type)
{
float octave[7]={130.81,146.83,164.81,174.61,196,220,246.94};
int n,i;
switch(type)
{
case 1:
for(i=0;i<7;i++)
{
sound(octave[i]*8);
delay(30);
}
nosound();
break;
case 2:
for(i=4;i>=0;i--)
{
sound(octave[i]*4);
delay(15);
}
nosound();
break;
case 3:
sound(octave[6]*2);
delay(20);
nosound();
break;
case 4:
sound(530);
delay(60);
nosound();
}
return(type);
}
void main(void)
{
void *mouse;
unsigned int area;
int x,y,m,k00=0,k11=0,k22=0,k1=0,k2=0,k3=0,k4=0,tt1,tt2,tt3,tt4,capslock=0;
char *mm,MMM1[]={'Q','W','E','R','T','Y','U','I','O','P'};
char MMM2[]={'A','S','D','F','G','H','J','K','L'};
char MMM3[]={'Z','X','C','V','B','N','M'};
char MMM4[]={'1','2','3','4','5','6','7','8','9','0'};
char MMM11[]={'q','w','e','r','t','y','u','i','o','p'};
char MMM22[]={'a','s','d','f','g','h','j','k','l'};
char MMM33[]={'z','x','c','v','b','n','m'};
char MMM44[]={'!','@','#','$','%','^','&','*','(',')'};
gotoxy(1,1);
initgraph(&gdriver,&gmode,"F:\\TC\\BGI");
cleardevice();
setcolor(12);
line(65,45,560,45);
line(65,48,560,48);
setcolor(3);
settextstyle(10,0,1);
outtextxy(90,1,"My mouse controlled keyboard");
setcolor(8);
settextstyle(0,0,2);
outtextxy(35,380,"Created by:");
setcolor(9);
settextstyle(10,0,1);
outtextxy(20,55,"Type:");
setcolor(9);
settextstyle(0,0,3);
outtextxy(130,420,"MD. MOHIUDDIN AHMED");
setfillstyle(6,8);
bar(2,120,620,350);
setcolor(3);
rectangle(2,120,620,350);
rectangle(2-1,120-1,620+1,350+1);
rectangle(2-2,120-2,620+2,350+2);
setfillstyle(1,2);
setcolor(3);
settextstyle(0,0,2);
for(u=0,v=0;u<10;u++,v+=60)
{
setcolor(0);
setfillstyle(1,u+1);
bar(30+v,140,50+v,160);
sprintf(mm,"%c",MMM1[u]);
outtextxy(30+v+2,142,mm);
}
for(u=0,v=0;u<9;u++,v+=60)
{
setcolor(0);
setfillstyle(1,u+1);
bar(55+v,180,75+v,200);
sprintf(mm,"%c",MMM2[u]);
outtextxy(55+v+2,182,mm);
}
for(u=0,v=0;u<7;u++,v+=60)
{
setcolor(0);
setfillstyle(1,u+1);
bar(90+v,220,110+v,240);
sprintf(mm,"%c",MMM3[u]);
outtextxy(90+v+2,222,mm);
}
for(u=0,v=0;u<10;u++,v+=60)
{
setcolor(0);
setfillstyle(1,u+1);
bar(30+v,300,50+v,320);
sprintf(mm,"%c",MMM4[u]);
outtextxy(30+v+2,302,mm);
}
setfillstyle(1,12);
bar(160,260,370,280);
setfillstyle(1,3);
bar(30,260,100,280);
setfillstyle(1,9);
bar(411,261,549,279);
setfillstyle(1,8);
bar(490,250,510,255);
setcolor(0);
rectangle(32,262,98,278);
rectangle(412,262,548,278);
settextstyle(0,0,1);
outtextxy(38,267,"Delete");
outtextxy(438,267,"Caps Lock");
setcolor(11);
settextstyle(0,0,2);
moveto(107,77);
x=100;
y=100;
cursor_on();
setcolor(8);
circle(x,y,5);
setcolor(7);
circle(x,y,4);
setcolor(14);
circle(x,y,3);
setcolor(12);
circle(x,y,2);
setfillstyle(1,12);
floodfill(x,y,12);
area=imagesize(x-5,y-5,x+5,y+5);
mouse=malloc(area);
getimage(x-5,y-5,x+5,y+5,mouse);
setfillstyle(1,0);
bar(x-5,y-5,x+5,y+5);
setcolor(3);
while(1)
{ mouse_position(&x,&y);
if(x>getmaxx()-10)
x=getmaxx()-10;
if(y>getmaxy()-10)
y=getmaxy()-10;
putimage(x,y,mouse,XOR_PUT);
for(u=0,v=0;u<10;u++,v+=60)
{
if((x>=30+v)&&(x<=50+v)&&(y>=140)&&(y<=160))
{
if(k1==0)
{
tt1=v;
sound(600);
delay(30);
nosound();
k1=1;
}
rectangle(30+v-1,140-1,50+v+1,160+1);
rectangle(30+v-2,140-2,50+v+2,160+2);
}
else
{
if(tt1==v)
k1=0;
setcolor(0);
rectangle(30+v-1,140-1,50+v+1,160+1);
rectangle(30+v-2,140-2,50+v+2,160+2);
setcolor(11);
}
}
for(u=0,v=0;u<9;u++,v+=60)
{
if((x>=55+v)&&(x<=75+v)&&(y>=180)&&(y<=200))
{
if(k2==0)
{
tt2=v;
sound(600);
delay(30);
nosound();
k2=1;
}
rectangle(55+v-1,180-1,75+v+1,200+1);
rectangle(55+v-2,180-2,75+v+2,200+2);
}
else
{
if(tt2==v)
k2=0;
setcolor(0);
rectangle(55+v-1,180-1,75+v+1,200+1);
rectangle(55+v-2,180-2,75+v+2,200+2);
setcolor(11);
}
}
for(u=0,v=0;u<7;u++,v+=60)
{
if((x>=90+v)&&(x<=110+v)&&(y>=220)&&(y<=240))
{
if(k3==0)
{
tt3=v;
sound(600);
delay(30);
nosound();
k3=1;
}
rectangle(90+v-1,220-1,110+v+1,240+1);
rectangle(90+v-2,220-2,110+v+2,240+2);
}
else
{
if(tt3==v)
k3=0;
setcolor(0);
rectangle(90+v-1,220-1,110+v+1,240+1);
rectangle(90+v-2,220-2,110+v+2,240+2);
setcolor(11);
}
}
for(u=0,v=0;u<10;u++,v+=60)
{
if((x>=30+v)&&(x<=50+v)&&(y>=300)&&(y<=320))
{
if(k4==0)
{
tt4=v;
sound(600);
delay(30);
nosound();
k4=1;
}
rectangle(30+v-1,300-1,50+v+1,320+1);
rectangle(30+v-2,300-2,50+v+2,320+2);
}
else
{
if(tt4==v)
k4=0;
setcolor(0);
rectangle(30+v-1,300-1,50+v+1,320+1);
rectangle(30+v-2,300-2,50+v+2,320+2);
setcolor(11);
}
}
if(x>=160&&x<=370&&y>=260&&y<=280)
{
if(k00==0)
{
sound(600);
delay(30);
nosound();
k00=1;
}
rectangle(160-1,260-1,370+1,280+1);
rectangle(160-2,260-2,370+2,280+2);
}
else
{
k00=0;
setcolor(0);
rectangle(160-1,260-1,370+1,280+1);
rectangle(160-2,260-2,370+2,280+2);
setcolor(11);
}
if(x>=30&&x<=100&&y>=260&&y<=280)
{
if(k11==0)
{
sound(600);
delay(30);
nosound();
k11=1;
}
rectangle(30-1,260-1,100+1,280+1);
rectangle(30-2,260-2,100+2,280+2);
}
else
{
k11=0;
setcolor(0);
rectangle(30-1,260-1,100+1,280+1);
rectangle(30-2,260-2,100+2,280+2);
setcolor(11);
}
if(x>=411&&x<=549&&y>=261&&y<=279)
{
if(k22==0)
{
sound(600);
delay(30);
nosound();
k22=1;
}
rectangle(411-1,261-1,549+1,279+1);
rectangle(411-2,261-2,549+2,279+2);
}
else
{
k22=0;
setcolor(0);
rectangle(411-1,261-1,549+1,279+1);
rectangle(411-2,261-2,549+2,279+2);
setcolor(11);
}
if(rightb_pressed())
{
free(mouse);
cursor_off();
closegraph();
restorecrtmode();
exit(0);
}
if(leftb_pressed())
{
for(u=0,v=0;u<10;u++,v+=60)
{
if((x>=30+v)&&(x<=50+v)&&(y>=140)&&(y<=160))
{
music(4);
if(capslock==1)
sprintf(mm,"%c",MMM1[u]);
else
sprintf(mm,"%c",MMM11[u]);
outtext(mm);
}
}
for(u=0,v=0;u<9;u++,v+=60)
{
if((x>=55+v)&&(x<=75+v)&&(y>=180)&&(y<=200))
{
music(4);
if(capslock==1)
sprintf(mm,"%c",MMM2[u]);
else
sprintf(mm,"%c",MMM22[u]);
outtext(mm);
}
}
for(u=0,v=0;u<7;u++,v+=60)
{
if((x>=90+v)&&(x<=110+v)&&(y>=220)&&(y<=240))
{
music(4);
if(capslock==1)
sprintf(mm,"%c",MMM3[u]);
else
sprintf(mm,"%c",MMM33[u]);
outtext(mm);
}
}
for(u=0,v=0;u<10;u++,v+=60)
{
if((x>=30+v)&&(x<=50+v)&&(y>=300)&&(y<=320))
{
music(4);
if(capslock==0)
sprintf(mm,"%c",MMM4[u]);
else
sprintf(mm,"%c",MMM44[u]);
outtext(mm);
}
}
if(x>=160&&x<=370&&y>=260&&y<=280)
{
music(2);
outtext(" ");
}
if(x>=30&&x<=100&&y>=260&&y<=280)
{
music(1);
setviewport(105,55,getmaxx(),110,1);
clearviewport();
setviewport(0,0,getmaxx(),getmaxy(),1);
moveto(107,77);
}
if(x>=411&&x<=549&&y>=261&&y<=279)
{
music(3);
if(capslock==0)
{
capslock=1;
setfillstyle(1,10);
bar(490,250,510,255);
}
else
{
capslock=0;
setfillstyle(1,8);
bar(490,250,510,255);
}
}
while(leftb_pressed());
}
putimage(x,y,mouse,XOR_PUT);
}
}
No comments:
Post a Comment