Welcome To Ree-blog.tk any question?chat with us on Facebook "COMING SOON'

Senin, 03 Juni 2013

Mungkin fungsi ShortCut HotKey ini berbeda dengan yang biasa di buat pada menu. Karena ShortCut HotKey ShortCut yang merupakan yang bersifat global di Komputer atau laptop anda . Atau juga bisa di bilang Shortcut ini berlaku walaupun aplikasi Anda tidak dalam keadaan focus.






Berikut cara membuatnya :
Untuk Visual Basic 6.0 , buatkan sebuah module baru dan ketikan ini :


Declare Function RegisterHotKey Lib "user32.dll" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As LongDeclare Function UnregisterHotKey Lib "user32.dll" (ByVal hwnd As Long, ByVal id As Long) As Long Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public lHotKey As Long
Public Const WM_HOTKEY = &H312 Public Const GWL_WNDPROC = -4
Public Const MOD_ALT = &H1 Public Const MOD_CTRL = &H2 Public Const MOD_SHIFT = &H4 Public Const MOD_WIN = &H8
'id dari masing2 shortcut Public Const idPerintah1 = 101 Public Const idPerintah2 = 102 Public Const idPerintah3 = 103
Public Function CallbackMsgs(ByVal wHwnd As Long, ByVal wMsg As Long, ByVal wp_id As Long, ByVal lp_id As Long) As Long If wMsg = WM_HOTKEY Then
Form1.Show 'set focus Select Case wp_id Case idPerintah1 Msgbox "Perintah 1 dijalankan ." Case idPerintah2Msgbox "Perintah 2 dijalankan ."
Case idPerintah3Msgbox "Perintah 3 dijalankan ."
End Select    
CallbackMsgs = 1 Else CallbackMsgs = CallWindowProc(lHotKey, wHwnd, wMsg, wp_id, lp_id) End If End Function


Di bagian 'Form_Load' ketikkan :
RegisterHotKey Me.hwnd, idPerintah1, MOD_CTRL + MOD_SHIFT, Asc("P") 'Ctrl + Shift + P RegisterHotKey Me.hwnd, idPerintah2, MOD_CTRL + MOD_SHIFT + MOD_ALT, Asc("Q") 'Ctrl + Shift + Alt + Q RegisterHotKey Me.hwnd, idPerintah3, MOD_WIN, Asc("G") 'WinKey + G
lHotKey = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf CallbackMsgs)

Di bagian 'Form_Unload' ketikkan :
UnregisterHotKey Me.hwnd, idPerintah1 UnregisterHotKey Me.hwnd, idPerintah2 UnregisterHotKey Me.hwnd, idPerintah3

Kemudian untuk VB.NET

Di bagian '(Declarations)' dari Form ketikkan :

Private Declare Function RegisterHotKey Lib "user32.dll" (ByVal hwnd As Integer, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer Private Declare Function UnregisterHotKey Lib "user32.dll" (ByVal hwnd As Integer, ByVal id As Integer) As Integer Const WM_HOTKEY = &H312
Const MOD_ALT = &H1 Const MOD_CTRL = &H2 Const MOD_SHIFT = &H4 Const MOD_WIN = &H8
'id dari masing2 shortcut Const idPerintah1 = 101 Const idPerintah2 = 102 Const idPerintah3 = 103
Protected Overrides Sub WndProc(ByRef m As Message) MyBase.WndProc(m) If m.Msg = WM_HOTKEY Then AppActivate(System.Diagnostics.Process.GetCurrentProcess.Id) 'set focus Select Case m.WParam.ToInt32 Case idPerintah1 Msgbox "Perintah 1 dijalankan " Case idPerintah2Msgbox "Perintah 2 dijalankan "
Case idPerintah3Msgbox "Perintah 3 dijalankan "
End Select End If End Sub

Di bagian 'Form1_Load' ketikkan :
RegisterHotKey(Me.Handle.ToInt32, idPerintah1, MOD_CTRL + MOD_SHIFT, Asc("P")) 'Ctrl + Shift + P RegisterHotKey(Me.Handle.ToInt32, idPerintah2, MOD_CTRL + MOD_SHIFT + MOD_ALT, Asc("Q")) 'Ctrl + Shift + Alt + Q RegisterHotKey(Me.Handle.ToInt32, idPerintah3, MOD_WIN, Asc("G")) 'WinKey + G

Di bagian 'Form1_FormClosed' ketikkan :
UnregisterHotKey(Me.Handle.ToInt32, idPerintah1) UnregisterHotKey(Me.Handle.ToInt32, idPerintah2) UnregisterHotKey(Me.Handle.ToInt32, idPerintah3)

0 komentar:

Posting Komentar