|
이전에 특수 키보드를 사용하기 위하여, 후킹을 사용한 적이 있었습니다. 소스도 간단하니 올려드릴께요. 불행하게도(?) Tray 처리 부분과 섞여있습니다... -_-a
[헤더 파일]
//---------------------------------------------------------------------------
#ifndef Unit_RemoteH
#define Unit_RemoteH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <AppEvnts.hpp>
#include <ScktComp.hpp>
#include <Menus.hpp>
#include <NMUDP.hpp>
#include "CSPIN.h"
#define KEY_EXTENSION 0x000000FF
#define KEY_1 0xC0670001
#define KEY_2 0xC0660001
#define KEY_3 0xC15A0001
#define KEY_4 0xC1660001
#define KEY_5 0xC1670001
#define KEY_ADSL 0xC0550001
#define KEY_NETWORK 0xC16A0001
#define KEY_MOVIE 0xC05A0001
#define KEY_MENU 0xC1210001
#define KEY_INTERNET 0xC0590001
#define KEY_BACK 0xC16B0001
//---------------------------------------------------------------------------
class TMain : public TForm
{
__published: // IDE-managed Components
TApplicationEvents *Event;
void __fastcall FormDestroy(TObject *Sender);
void __fastcall EventRestore(TObject *Sender);
void __fastcall MI_ExitClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormActivate(TObject *Sender);
private: // User declarations
void __fastcall TrayEvent(TMessage &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_USER + 1, TMessage, TrayEvent)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TMain(TComponent* Owner);
void __fastcall TMain::AddTray();
void __fastcall TMain::RemoveTray();
};
//---------------------------------------------------------------------------
extern PACKAGE TMain *Main;
//---------------------------------------------------------------------------
#endif
[소스 파일]
/**************************************************************/
/* Hi-Net Linux - Windows Input Device Communicator */
/* */
/* Man & Tech Cuperido */
/**************************************************************/
#include <vcl.h>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#pragma package(smart_init)
#include "Unit_Remote.h"
#pragma hdrstop
#pragma resource "*.dfm"
TMain *Main;
UINT uiTrayMessage;
bool blSituation, blCertification = false;
HHOOK HOOKKEY;
LRESULT CALLBACK KeyboardProc(int itCode, WPARAM wpParam, LPARAM lpParam);
/****************************************************************
Tmain
- Main Initialize
****************************************************************/
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{
// Receive Register Message From Windows
uiTrayMessage = RegisterWindowMessage ("MyIconNotify");
}
/****************************************************************
AddTray
- Add icon to tray-bar
****************************************************************/
void __fastcall TMain::AddTray()
{
NOTIFYICONDATA niIcon;
memset(&niIcon, 0x00, sizeof(niIcon));
niIcon.cbSize = sizeof(niIcon);
niIcon.hWnd = Handle;
strncpy(niIcon.szTip, "Hi-Net Keyboard", sizeof(niIcon.szTip));
niIcon.hIcon = Application->Icon->Handle;
niIcon.uCallbackMessage = WM_USER + 1;
niIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
Shell_NotifyIcon(NIM_ADD, &niIcon);
}
/****************************************************************
RemoveTray
- Remove icon from tray-bar
****************************************************************/
void __fastcall TMain::RemoveTray()
{
NOTIFYICONDATA niIcon;
memset(&niIcon, 0x00, sizeof(niIcon));
niIcon.cbSize = sizeof(niIcon);
niIcon.hWnd = Handle;
Shell_NotifyIcon(NIM_DELETE, &niIcon);
}
/****************************************************************
FormDestroy
- Destory processing
****************************************************************/
void __fastcall TMain::FormDestroy(TObject *Sender)
{
UnhookWindowsHookEx(HOOKKEY);
RemoveTray();
}
/****************************************************************
EventRestore
- Send SW_HIDE message to windows when windows was opened
****************************************************************/
void __fastcall TMain::EventRestore(TObject *Sender)
{
ShowWindow(Application->Handle, SW_HIDE);
}
/****************************************************************
MI_ExitClick
- Exit processing
****************************************************************/
void __fastcall TMain::MI_ExitClick(TObject *Sender)
{
// Disable close Event
Main->OnCloseQuery = NULL;
Main->Close();
}
/****************************************************************
TrayEvent
- Process tray-bar event
****************************************************************/
void __fastcall TMain::TrayEvent(TMessage &Msg)
{
}
/****************************************************************
FormCreate
- Form initialize event
****************************************************************/
void __fastcall TMain::FormCreate(TObject *Sender)
{
AddTray();
blSituation = True;
SystemParametersInfo(SPI_SCREENSAVERRUNNING, true, NULL, 0);
EnableWindow(FindWindowEx(FindWindow("Shell_TrayWnd", NULL), 0, "Button", NULL), false);
ShowWindow(FindWindow(NULL, "ShellTrayWnd"), SW_HIDE);
HOOKKEY = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, HInstance, 0);
}
LRESULT CALLBACK KeyboardProc(int itCode, WPARAM wpParam, LPARAM lpParam)
{
TShiftState ssTemp;
BYTE btVKey = 0, btSKey = 0;
if(wpParam == KEY_EXTENSION) {
switch(lpParam) {
case KEY_1 : btVKey = 49; btSKey = 49; break;
case KEY_2 : btVKey = 50; btSKey = 50; break;
case KEY_3 : btVKey = 51; btSKey = 51; break;
case KEY_4 : btVKey = 52; btSKey = 52; break;
case KEY_5 : btVKey = 53; btSKey = 53; break;
case KEY_ADSL : btVKey = VK_F13; btSKey = 1; break;
case KEY_NETWORK : btVKey = VK_F14; btSKey = 1; break;
case KEY_MOVIE : btVKey = VK_F15; btSKey = 1; break;
case KEY_MENU : btVKey = VK_F16; btSKey = 1; break;
case KEY_INTERNET : btVKey = VK_F17; btSKey = 1; break;
case KEY_BACK : btVKey = VK_F18; btSKey = 1; break;
}
}
if(btVKey && btSKey) {
keybd_event(btVKey, btSKey, 0, 0);
keybd_event(btVKey, btSKey, KEYEVENTF_KEYUP, 0);
}
return(0);
}
void __fastcall TMain::FormActivate(TObject *Sender)
{
ShowWindow(Application->Handle, SW_HIDE);
Main->Left = Screen->Width + 10;
Main->Top = Screen->Height + 10;
}
//---------------------------------------------------------------------------
알베르또 님이 쓰신 글 :
: 검색을 해 봤는 데 못 찾았습니다. 하느리님ID로도 검색해봤는 데 그중에서도 훗킹관련된 내용은 찾지 못했습니다. 오래되어 내용이 삭제된 것은 아닌가요?
:
: 하느리 님이 쓰신 글 :
: : 훗킹이라는 기법을 이용하면 됩니다.
: : 여기 게시판에서 훗킹이라고 검색해 보세요.
: : 제가 않되는 소스지만 질문 겸 해서 올려 놓은 소스도 있고 하니, 보시면 어떻게 하면 될겠는지 아실 수 있을 겁니다. 안되면 리플 달아 주세요. 자세히 설명드릴께요.
|