按鍵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]。