我前面說的只是編程的技巧,如果你單純是為了讓代碼好看,那么像我那么做即可,如果你是非要轉(zhuǎn)換鍵碼的鍵名,用下面的代碼:
在成都做網(wǎng)站、網(wǎng)站設計過程中,需要針對客戶的行業(yè)特點、產(chǎn)品特性、目標受眾和市場情況進行定位分析,以確定網(wǎng)站的風格、色彩、版式、交互等方面的設計方向。創(chuàng)新互聯(lián)公司還需要根據(jù)客戶的需求進行功能模塊的開發(fā)和設計,包括內(nèi)容管理、前臺展示、用戶權(quán)限管理、數(shù)據(jù)統(tǒng)計和安全保護等功能。
Private
Declare
Function
GetKeyNameText
Lib
"user32"
Alias
"GetKeyNameTextA"
(ByVal
lParam
As
Long,
ByVal
lpBuffer
As
String,
ByVal
nSize
As
Long)
As
Long
Private
Declare
Function
MapVirtualKey
Lib
"user32"
Alias
"MapVirtualKeyA"
(ByVal
wCode
As
Long,
ByVal
wMapType
As
Long)
As
Long
Private
Sub
Form_KeyDown(KeyCode
As
Integer,
Shift
As
Integer)
Dim
s
As
String
s
=
String(100,
Chr(0))
GetKeyNameText
MapVirtualKey(KeyCode,
0)
*
65536,
s,
100
s
=
Left(s,
InStr(s,
Chr(0)))
Me.Cls
s
End
Sub
===================================
VB中有預先定義好的鍵碼的常量
你添加這樣的定義類型
Dim
k
As
KeyCodeConstants
然后你鍵入
k
=就可以看到很多常量的選項,就包括所有的虛擬鍵碼
不明白的百度HI我,樓上說的那些方法都不對
===================================
用API函數(shù),以下代碼Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Const WS_EX_LAYERED = H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = H2
Private Const LWA_COLORKEY = H1Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMosT = -1
Private Const SWP_NOMOVE = H2
Private Const SWP_NosIZE = H1
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_KEYDOWN = H100
Const WM_KEYUP = H101
Const WM_CHAR = H102
Const VK_F1 = H70
Private Sub SendF1(hwnd) '調(diào)用這個過程即可對目標窗體發(fā)送F1鍵
Call PostMessage(hwnd, WM_KEYDOWN, VK_F1, 0)
Call PostMessage(hwnd, WM_KEYUP, VK_F1, 0)
End Sub這里是發(fā)送F1的實例,各個按鍵對應的虛擬鍵碼,要到網(wǎng)上查
第三句。在類級別的變量聲明語句中必須顯式指定類型名稱,省略AS語句只可以用在局部變量聲明語句中。
Private Const c As String = "ok"
常量,是指程序在運行過程中其值可以改變的量;在VB中值常量就是一個固定不變的值,不能修改,變量可以修改內(nèi)存空間對其進行修改不發(fā)生變化的叫常量 。
用Const定義的 在VB中不能參加賦值 比如 Const a as integer=30;隱式聲明,只是變量,不經(jīng)聲明,直接使用;顯示聲明,變量聲明后再使用的方式成為顯式聲明。
擴展資料:
VB變量類型轉(zhuǎn)換規(guī)則:
數(shù)據(jù)型變量之間可以相互賦值。
浮點數(shù)轉(zhuǎn)換為整型數(shù)時,小數(shù)部分“四舍五入”為整數(shù)(其中0.5要向最近的偶數(shù)靠攏)。
當給一個變量賦予超出它表示范圍的值時,會導致“溢出”錯誤。
例如:
(1)? ?intN1=45631234? ?'(超出整型變量范圍,系統(tǒng)提示溢出錯誤)。
(2)? ?bytN1=-12 '(超出表示范圍,報溢出錯誤)。
參考資料來源:
百度百科-常量