按键c语言程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=
{
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
};
sbit key1=P3^4;
uchar num=0;
void delay(uint z);
void main()
{
while(1)
{
P2=0xfe;
P0=table[num];
delay(50);
if(key1==0)
{
while(!key1);
num++;
};
if(num==10)
{
num=0;
};
}
}
void delay(uint z)
{
while(z--);
}
2. 在C语言中如何实现按任意键继续
1、直接调用系统函数 system("pause"):
system()会调用fork()产生子进程, 由子进程来调用/bin/sh-c string 来执行参数string 字符串所代表的命令, 此命令执行完后随即返回原调用的进程。
system("pause")可以实现冻结屏幕,便于观察程序的执行结果。如下:
3. 如何用C语言写一个button按钮
#include <windows.h>
typedef _Bool bool;
#define false ((bool)0)
#define true ((bool)1)
HWND ChuangJianChuangKou(char *a,bool(*b)(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam),bool c,int x,int y)
{
HWND hwnd;
static TCHAR szAppName[] = TEXT("Mz Game") ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC ;
wndclass.lpszClassName = szAppName ;
wndclass.lpszMenuName = NULL ;
wndclass.hbrBackground =(HBRUSH)GetStockObject(6);
wndclass.lpfnWndProc = (WNDPROC)b;
wndclass.cbWndExtra = 0 ;
wndclass.cbClsExtra = 0 ;
wndclass.hInstance = 0;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION ) ;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ) ;
if(!RegisterClass(&wndclass))
{
return (HWND)0;
}
hwnd=CreateWindow(
szAppName,
a,
c?WS_OVERLAPPEDWINDOW:WS_POPUP,
(GetSystemMetrics (SM_CXSCREEN)-x)/2,
(GetSystemMetrics (SM_CYSCREEN)-y)/2,
x,
y,
0,
0,
0,
0
);
ShowWindow(hwnd,1);
UpdateWindow(hwnd);
return hwnd;
}
bool GengXinChuangKou()
{
static MSG msg;
if(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return true;
}
else
{
return false;
}
}
bool WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
return MoRenChuLi(hwnd,message,wParam,lParam,0);
}
WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
ChuangJianChuangKou("sss",WndProc,true,KongJianDaXiao(0).x/2,KongJianDaXiao(0).y/2);
while(GengXinChuangKou());
}
4. 在c语言中怎么实现输入esc退出 其他键继续
#include <conio.h>
#include <stdio.h>
int main(){
while(1){
if (_kbhit() && _getch()==0x1b)
break;
printf("continue");
}
}
(4)按键c语言程序扩展阅读:
1、kbhit()
功能及返回值: 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0。
用法:int kbhit(void);
2、getch():
所在头文件:conio.h
函数用途:从控制台读取一个字符,但不显示在屏幕上
函数原型:int getch(void)
返回值:读取的字符
5. C语言如何模拟键盘输入
C语言模拟键盘代码如下:
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
{
MSG msg;
if(!MyRegisterClass(hInstance))
{
return FALSE;
}
if(!InitInstance(hInstance,iCmdShow))
{
return FALSE;
}
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
//函数:ShowKey
//作用:实现在窗口中显示按键信息
void ShowKey (HWND hwnd, int iType,char *szMessage,WPARAM wParam,LPARAM lParam)
{
static char *szFormat[2] ={"%-14s %3d %c %6u %4d %5s %5s %6s %6s",
"%-14s %3d %c %6u %4d %5s %5s %6s %6s" };
char szBuffer[80];
HDC hdc;
ScrollWindowEx(hwnd, 0, -yChar, &rc,&rc,NULL,NULL,SW_INVALIDATE);
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
TextOut (hdc,
xChar,
rc.bottom - yChar,
szBuffer,
wsprintf szBuffer,
szFormat[iType]。