static void Win_DisableAltTab( void ) { if( !win.alttab_disabled ) { RegisterHotKey( 0, 0, MOD_ALT, VK_TAB ); RegisterHotKey( 0, 1, MOD_ALT, VK_RETURN ); win.alttab_disabled = qtrue; } }
void CHotkeyDialog::OnBnClickedOk() { UINT mod, vkey; CString modifierstring; modifier.GetLBText(modifier.GetCurSel(),modifierstring); CString vkeystr; vchar.GetLBText(vchar.GetCurSel(),vkeystr); mod = szKeyToIdent(modifierstring); vkey = szKeyToIdent(vkeystr); UnregisterHotKey(AfxGetMainWnd()->GetSafeHwnd(), 100); BOOL m_isKeyRegistered = RegisterHotKey(AfxGetMainWnd()->GetSafeHwnd(), 100, mod, vkey); CLaunchyDlg* main_dlg = (CLaunchyDlg*) AfxGetMainWnd(); if (!m_isKeyRegistered) { AfxMessageBox(_T("Sorry, this hotkey will not work, please choose another")); // ReRegister the old hot key UnregisterHotKey(AfxGetMainWnd()->GetSafeHwnd(), 100); BOOL m_isKeyRegistered = RegisterHotKey(AfxGetMainWnd()->GetSafeHwnd(), 100, main_dlg->options->mod_key, main_dlg->options->vkey); } else { // Save the new hot key to ini main_dlg->options->vkey = vkey; main_dlg->options->mod_key = mod; OnOK(); } }
BOOL CCgxDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 ShowWindow(SW_NORMAL); // TODO: 在此添加额外的初始化代码 //InitializeWinIo(); #ifdef DEBUG RegisterHotKey(this->m_hWnd, HOTKEY_F2, 0, VK_F2); isTestDlgOpen = FALSE; #endif RegisterHotKey(this->m_hWnd, HOTKEY_F5, 0, VK_F5); RegisterHotKey(this->m_hWnd, HOTKEY_F6, 0, VK_F6); RegisterHotKey(this->m_hWnd, HOTKEY_F7, 0, VK_F7); OnBnClickedRefresh(); _initConfigFile(); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE }
/* Thread safe - doesn't care about the lock */ int HotkeysRegister(HWND hwnd, WORD ManSync, WORD OperModeSwitch) { UINT ManSyncModifiers = 0; UINT OperModeSwitchModifiers = 0; UINT ManSyncVk; UINT OperModeSwitchVk; /* Perform conversion of the format we got from HKM_GETHOTKEY To the format needed by RegisterHotkey() */ if (HOTKEYF_ALT & HIBYTE(ManSync)) ManSyncModifiers |= MOD_ALT; if (HOTKEYF_CONTROL & HIBYTE(ManSync)) ManSyncModifiers |= MOD_CONTROL; if (HOTKEYF_SHIFT & HIBYTE(ManSync)) ManSyncModifiers |= MOD_SHIFT; ManSyncVk = LOBYTE(ManSync); if (HOTKEYF_ALT & HIBYTE(OperModeSwitch)) OperModeSwitchModifiers |= MOD_ALT; if (HOTKEYF_CONTROL & HIBYTE(OperModeSwitch)) OperModeSwitchModifiers |= MOD_CONTROL; if (HOTKEYF_SHIFT & HIBYTE(OperModeSwitch)) OperModeSwitchModifiers |= MOD_SHIFT; OperModeSwitchVk = LOBYTE(OperModeSwitch); if(!(RegisterHotKey(hwnd, 443, ManSyncModifiers, ManSyncVk))) debuglog(DEBUG_ERROR,"Failed registering manual sync hotkey\n"); if(!(RegisterHotKey(hwnd, 444, OperModeSwitchModifiers, OperModeSwitchVk))) debuglog(DEBUG_ERROR,"Failed registering mode switch hotkey\n"); return 1; }
//=========================================================================== void AppleWin_RegisterHotKeys(void) { BOOL bStatus = true; bStatus &= RegisterHotKey( g_hFrameWindow , // HWND hWnd VK_SNAPSHOT_560, // int id (user/custom id) 0 , // UINT fsModifiers VK_SNAPSHOT // UINT vk = PrintScreen ); bStatus &= RegisterHotKey( g_hFrameWindow , // HWND hWnd VK_SNAPSHOT_280, // int id (user/custom id) MOD_SHIFT , // UINT fsModifiers VK_SNAPSHOT // UINT vk = PrintScreen ); bStatus &= RegisterHotKey( g_hFrameWindow , // HWND hWnd VK_SNAPSHOT_TEXT, // int id (user/custom id) MOD_CONTROL , // UINT fsModifiers VK_SNAPSHOT // UINT vk = PrintScreen ); if (!bStatus && g_bShowPrintScreenWarningDialog) { MessageBox( g_hFrameWindow, "Unable to capture PrintScreen key", "Warning", MB_OK ); } }
BOOL ClianliankanDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 if (!GetChessBase()) { AfxMessageBox(_T("获得系统信息失败!")); return FALSE; } if (!RegisterHotKey(m_hWnd, 100613, MOD_CONTROL, 0x31)) { AfxMessageBox(_T("热键CTRL+1绑定失败!")); return FALSE; } if (!RegisterHotKey(m_hWnd, 100614, MOD_CONTROL, 0x32)) { AfxMessageBox(_T("热键CTRL+2绑定失败!")); return FALSE; } m_iDelay = 200; UpdateData(FALSE); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE }
int main() { int i, slot, mtoggle = 0; MSG msg = {0}; HWND window_handles[10]; RECT window_rect; // Register hotkeys 0-9 for (i = 0; i < 10; i++) { if (RegisterHotKey(NULL, i, MOD_ALT, 0x30 + i) == TRUE) { printf("Registering Alt+%d as hotkey\n", i); } else { printf("Failed to register Alt+%d as hotkey\n", i); return 1; } if (RegisterHotKey(NULL, 10 + i, MOD_SHIFT | MOD_ALT, 0x30 + i) == TRUE) { printf("Registering Alt+Shift+%d as hotkey\n", i); } else { printf("Failed to register Alt+Shift+%d as hotkey\n", i); return 1; } window_handles[i] = 0; } if (RegisterHotKey(NULL, 20, MOD_SHIFT | MOD_ALT, 0x30 + 0x1D) == TRUE) { printf("Registered Alt+Shift+M as mouse toggle hotkey\n"); } while (GetMessage(&msg, NULL, 0, 0) != 0) { if (msg.message == WM_HOTKEY) { slot = (msg.lParam >> 16) - 0x30; if (slot == 0x1D) { // Mouse toggle hotkey printf("Mouse centering %sabled.\n", mtoggle ? "dis" : "en"); mtoggle = !mtoggle; continue; } if (msg.lParam & MOD_SHIFT) { /* Shift is pressed, register this window */ window_handles[slot] = GetForegroundWindow(); printf("Slot %d: Registering window %d\n", slot, window_handles[slot]); } else { /* Shift is not pressed, show this window */ if (window_handles[slot] == 0) { printf("Slot %d: Cannot show - no window registered\n", slot); } else { SetForegroundWindow(window_handles[slot]); if (mtoggle) { ZeroMemory(&window_rect, sizeof(RECT)); if (GetWindowRect(window_handles[slot], &window_rect) == FALSE) { printf("Could not get window dimensions.\n"); continue; } if (SetCursorPos((window_rect.left + window_rect.right)/2, (window_rect.top + window_rect.bottom)/2) == FALSE) { printf("Could not set cursor position.\n"); continue; } } printf("Slot %d: Showing window %d\n", slot, window_handles[slot]); } } } }
DWORD WINAPI YAMNHotKeyThread(LPVOID Param) { MSG WinMessage; WORD HotKey = LOWORD(Param); int HotKeyID; // register hotkey for main YAMN thread first if(!(HotKeyID=RegisterHotKey(NULL,(int)GlobalAddAtom(YAMN_HKCHECKMAIL),HIBYTE(HotKey),LOBYTE(HotKey)))) return 0; while(1) { GetMessage(&WinMessage,NULL,WM_HOTKEY,WM_YAMN_CHANGEHOTKEY); // if we want to close miranda, we get event and do not run pop3 checking anymore if(WAIT_OBJECT_0==WaitForSingleObject(ExitEV,0)) break; switch(WinMessage.message) { // user pressed hotkey case WM_HOTKEY: ForceCheckSvc((WPARAM)0,(LPARAM)0); break; // hotkey changed case WM_YAMN_CHANGEHOTKEY: UnregisterHotKey(NULL,HotKeyID); HotKeyID=RegisterHotKey(NULL,(int)GlobalAddAtom(YAMN_HKCHECKMAIL),WinMessage.wParam,WinMessage.lParam); break; } } return 1; }
static BOOL OnCreate(HWND hwnd) { g_ImageList = new CImageList(); g_ImageList->Create(); LOGFONT logfont; NONCLIENTMETRICS NcMetrics; NcMetrics.cbSize = sizeof(NONCLIENTMETRICS); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NcMetrics, 0); logfont = NcMetrics.lfMenuFont; logfont.lfHeight = 15; logfont.lfWeight = FW_NORMAL; logfont.lfQuality = DEFAULT_QUALITY; g_NormalFont = CreateFontIndirect(&logfont); logfont.lfItalic = TRUE; g_LaunchFont = CreateFontIndirect(&logfont); g_AppMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU1)); SendMessage(hwnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)GetResourceIconHandle(false)); SendMessage(hwnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)GetResourceIconHandle(true)); CreateNotifyIcon(hwnd); #if ENABLE_HOOK Hook(hwnd, WM_SP_KEYDOWN, WM_SP_KEYUP); #endif BOOL bResult; bResult = RegisterHotKey(hwnd, 0, MOD_ALT, VK_TAB); bResult = RegisterHotKey(hwnd, 1, MOD_ALT|MOD_SHIFT, VK_TAB); return TRUE; }
int CDlgModelManage::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDialogEx::OnCreate(lpCreateStruct) == -1) return -1; RegisterHotKey(m_hWnd,1001,MOD_CONTROL|MOD_SHIFT|MOD_ALT,'K'); RegisterHotKey(m_hWnd,1002,MOD_CONTROL|MOD_SHIFT|MOD_ALT,'k'); return 0; }
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_HOTKEY: switch ( HIWORD( lParam ) ) { case VK_RIGHT: PostEvent( EVENT_TYPE_HOTKEY_NEXT ); break; case VK_SPACE: PostEvent( EVENT_TYPE_HOTKEY_PAUSE ); break; } break; case WM_WTSSESSION_CHANGE: switch ( wParam ) { case WTS_SESSION_LOCK: PostEvent( EVENT_TYPE_CONSOLE_LOCK ); break; case WTS_SESSION_UNLOCK: PostEvent( EVENT_TYPE_CONSOLE_UNLOCK ); break; } break; case WM_WINDOWPOSCHANGING: { WINDOWPOS * pPos = (WINDOWPOS*) lParam; pPos->flags |= SWP_HIDEWINDOW; pPos->flags &= ~SWP_SHOWWINDOW; } break; case WM_INITDIALOG: g_hwnd = hDlg; WTSRegisterSessionNotification( hDlg, NOTIFY_FOR_ALL_SESSIONS ); RegisterHotKey( g_hwnd, 1, MOD_ALT | MOD_CONTROL, VK_SPACE ); RegisterHotKey( g_hwnd, 2, MOD_ALT | MOD_CONTROL, VK_RIGHT ); return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }
void InitPasteSerial() { bInitPasteSerial=TRUE; if (nHotkeyDelimSkipID=GlobalAddAtomA("AkelPad::PasteSerial::DelimSkip")) RegisterHotKey(hMainWnd, nHotkeyDelimSkipID, GetHotkeyMod(dwHotkeyDelimSkip), LOBYTE(dwHotkeyDelimSkip)); if (nHotkeyDelimAsTabID=GlobalAddAtomA("AkelPad::PasteSerial::DelimAsTab")) RegisterHotKey(hMainWnd, nHotkeyDelimAsTabID, GetHotkeyMod(dwHotkeyDelimAsTab), LOBYTE(dwHotkeyDelimAsTab)); if (nHotkeyDelimAsIsID=GlobalAddAtomA("AkelPad::PasteSerial::DelimAsIs")) RegisterHotKey(hMainWnd, nHotkeyDelimAsIsID, GetHotkeyMod(dwHotkeyDelimAsIs), LOBYTE(dwHotkeyDelimAsIs)); }
void CPpcMainWnd::RegisterHotKeys() { if (m_fHotKey) return; int i, j; if (m_fHold) { for (i = 0; i < sizeof(s_uHoldKeys) / sizeof(UINT) / 2; i++) RegisterHotKey(m_hWnd, s_uHoldKeys[i][0], s_uHoldKeys[i][1], s_uHoldKeys[i][0]); CPpcOptions* pOptions = (CPpcOptions*)m_pOptions; for (i = 0; i < pOptions->m_listKeyMap.GetCount(); i++) { BOOL fHold = FALSE; ACCEL* p = (ACCEL*)pOptions->m_listKeyMap.GetAt(i); for (j = 0; j < sizeof(s_uHoldKeys) / sizeof(UINT) / 2; j++) { if (s_uHoldKeys[j][0] == p->key) { fHold = TRUE; break; } } if (!fHold) { UINT fsModifiers = 0; if (p->fVirt & FALT) fsModifiers |= MOD_ALT; if (p->fVirt & FCONTROL) fsModifiers |= MOD_CONTROL; if (p->fVirt & FSHIFT) fsModifiers |= MOD_SHIFT; if (p->fVirt & FWIN) fsModifiers |= MOD_WIN; RegisterHotKey(m_hWnd, p->key, fsModifiers, p->key); } } } else { CPpcOptions* pOptions = (CPpcOptions*)m_pOptions; for (i = 0; i < pOptions->m_listKeyMap.GetCount(); i++) { ACCEL* p = (ACCEL*)pOptions->m_listKeyMap.GetAt(i); UINT fsModifiers = 0; if (p->fVirt & FALT) fsModifiers |= MOD_ALT; if (p->fVirt & FCONTROL) fsModifiers |= MOD_CONTROL; if (p->fVirt & FSHIFT) fsModifiers |= MOD_SHIFT; if (p->fVirt & FWIN) fsModifiers |= MOD_WIN; RegisterHotKey(m_hWnd, p->key, fsModifiers, p->key); } } m_fHotKey = TRUE; }
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { RegisterHotKey(NULL, 1, MOD_SHIFT | MOD_ALT, 0x43); RegisterHotKey(NULL, 1, MOD_SHIFT | MOD_ALT, 0x4A); // Alt+Shift+J for Dvorak users MSG msg = { 0 }; while (GetMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY) != 0) SendMessage(GetForegroundWindow(), WM_SYSCOMMAND, SC_CLOSE, 0); return WM_QUIT; }
MediaKeyListener::MediaKeyListener (QObject *receiver) : QAbstractNativeEventFilter (), m_receiver(receiver) { #if defined Q_OS_WIN if (!RegisterHotKey (NULL, TO_WIN_KNUM(HotKey::Stop), MOD_NOREPEAT, VK_MEDIA_STOP)) { throw KeyNotBoundException () ; } if (!RegisterHotKey (NULL, TO_WIN_KNUM(HotKey::Play), MOD_NOREPEAT, VK_MEDIA_PLAY_PAUSE)) { throw KeyNotBoundException () ; } if (!RegisterHotKey (NULL, TO_WIN_KNUM (HotKey::Prev), MOD_NOREPEAT, VK_MEDIA_PREV_TRACK)) { throw KeyNotBoundException () ; } if (!RegisterHotKey (NULL, TO_WIN_KNUM (HotKey::Next), MOD_NOREPEAT, VK_MEDIA_NEXT_TRACK)) { throw KeyNotBoundException () ; } if (!RegisterHotKey (NULL, TO_WIN_KNUM (HotKey::AltStop), MOD_ALT | MOD_NOREPEAT, VK_MEDIA_STOP)) { throw KeyNotBoundException () ; } if (!RegisterHotKey (NULL, TO_WIN_KNUM (HotKey::AltPlay), MOD_ALT | MOD_NOREPEAT, VK_MEDIA_PLAY_PAUSE)) { throw KeyNotBoundException () ; } if (!RegisterHotKey (NULL, TO_WIN_KNUM (HotKey::AltPrev), MOD_ALT | MOD_NOREPEAT, VK_MEDIA_PREV_TRACK)) { throw KeyNotBoundException () ; } if (!RegisterHotKey (NULL, TO_WIN_KNUM (HotKey::AltNext), MOD_ALT | MOD_NOREPEAT, VK_MEDIA_NEXT_TRACK)) { throw KeyNotBoundException () ; } QEvent::registerEventType (HotKey::Stop); QEvent::registerEventType (HotKey::Play); QEvent::registerEventType (HotKey::Prev); QEvent::registerEventType (HotKey::Next); QEvent::registerEventType (HotKey::AltStop); QEvent::registerEventType (HotKey::AltPlay); QEvent::registerEventType (HotKey::AltPrev); QEvent::registerEventType (HotKey::AltNext); #endif }
/* ホットキー設定 */ BOOL SetHotKey(Cfg *cfg) { if (cfg->HotKeyCheck) { RegisterHotKey(GetMainWnd(), WM_SENDDLG_OPEN, cfg->HotKeyModify, cfg->HotKeySend); RegisterHotKey(GetMainWnd(), WM_RECVDLG_OPEN, cfg->HotKeyModify, cfg->HotKeyRecv); RegisterHotKey(GetMainWnd(), WM_DELMISCDLG, cfg->HotKeyModify, cfg->HotKeyMisc); } else { UnregisterHotKey(GetMainWnd(), WM_SENDDLG_OPEN); UnregisterHotKey(GetMainWnd(), WM_RECVDLG_OPEN); UnregisterHotKey(GetMainWnd(), WM_DELMISCDLG); } return TRUE; }
static BOOL Engine_Activate(TSEngine engine) { switch (engine) { default: assert(FALSE); return FALSE; case TSEngine_NONE: return TRUE; case TSEngine_SIMPLE: if (!RegisterHotKey(g_TSWindow, IDHK_NEXT, MOD_ALT, g_HotKey)) goto E1; if (!RegisterHotKey( g_TSWindow, IDHK_PREV, MOD_ALT|MOD_SHIFT, g_HotKey )) goto E2; return TRUE; E2: UnregisterHotKey(g_TSWindow, IDHK_NEXT); E1: return FALSE; case TSEngine_HOOK: { HINSTANCE hinstance; hinstance = (HINSTANCE)GetWindowLongPtr( g_TSWindow, GWLP_HINSTANCE ); g_HKeyHook = SetWindowsHookEx( WH_KEYBOARD_LL, TS_LowLevelKeyboardProc, hinstance, 0 ); if (g_HKeyHook == NULL) goto E3; if (!RegisterHotKey(g_TSWindow, IDHK_NEXT, MOD_ALT, g_HotKey)) goto E4; if (!RegisterHotKey( g_TSWindow, IDHK_PREV, MOD_ALT|MOD_SHIFT, g_HotKey )) goto E5; return TRUE; E5: UnregisterHotKey(g_TSWindow, IDHK_NEXT); E4: UnhookWindowsHookEx(g_HKeyHook); E3: return FALSE; } } }
// Method called when the timer has been edited void Timer::setNewData(int period, QKeySequence keySequence, UINT modifiers, UINT virtualKey, int hotkeyId) { // First, try to register the new hotkey if needed if ((this->virtualKey != virtualKey) || (this->modifiers != modifiers)) { if (!RegisterHotKey(nullptr, hotkeyId, modifiers | getNoRepeatFlag(), virtualKey)) { throw SMException(tr("failed to register the hotkey. No modification done.")); } UnregisterHotKey(nullptr, this->hotkeyId); this->hotkeyId = hotkeyId; } // Stop the timer if it's currently active bool active = this->timer->isActive(); stop(); // Update timer's data timer->setInterval(period * 1000); this->period = period; this->keySequence = keySequence; this->modifiers = modifiers; this->virtualKey = virtualKey; // Enable the timer if it was previously active if (active) { play(); } }
Timer::Timer(QString filename, int period, QKeySequence keySequence, UINT modifiers, UINT virtualKey, unsigned int hotkeyId) : filename(filename) , period(period) , keySequence(keySequence) , modifiers(modifiers) , virtualKey(virtualKey) , hotkeyId(hotkeyId) , broken(false) { // Register the hotkey (add the MOD_NOREPEAT flag) if (!RegisterHotKey(nullptr, hotkeyId, modifiers | getNoRepeatFlag(), virtualKey)) { throw SMException(tr("failed to register the hotkey.")); } // Create the player, the playlist and the media container this->mediaContent = new QMediaContent(filename); this->player = new QMediaPlayer(this); QMediaPlaylist* playlist = new QMediaPlaylist(this); // Give the media to the playlist, and the playlist to the player playlist->addMedia(*mediaContent); playlist->setPlaybackMode(QMediaPlaylist::CurrentItemOnce); player->setMedia(playlist); // Create the timer this->timer = new QTimer(this); this->timer->setInterval(period * 1000); // Connections connect(this->player, &QMediaPlayer::mediaStatusChanged, this, &Timer::mediaStatusChanged); connect(this->player, static_cast<void (QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error), this, &Timer::error); connect(this->timer, &QTimer::timeout, this, &Timer::playSound); connect(MainWindow::instance()->getNativeEventFilter(), &NativeEventFilter::hotkeyReceived, this, &Timer::togglePlayStop); }
/* ================ Con_SetFocus change focus to console hwnd ================ */ void Con_RegisterHotkeys( void ) { SetFocus( s_wcd.hWnd ); // user can hit escape for quit RegisterHotKey( s_wcd.hWnd, QUIT_ON_ESCAPE_ID, 0, VK_ESCAPE ); }
char _check_hotkeys( HWND hwnd, DWORD hotkeys[ ] ) { wchar_t display[400]; wchar_t key[200]; int k = 0; int j; for ( ; k < HOTKEYS; k++ ) { for ( j = 0; j < HOTKEYS; j++ ) { if ( k != j && hotkeys[k] && hotkeys[k] == hotkeys[j] ) { _key_name( HIWORD(hotkeys[k]), LOWORD(hotkeys[k]), key ); _snwprintf( display, sizeof_w(display), L"Duplicated Hotkey: \"%s\"", key ); MessageBox( hwnd, display, L"Error", MB_OK | MB_ICONERROR ); return FALSE; } } if ( hotkeys[k] && !RegisterHotKey( __dlg, k, LOWORD(hotkeys[k]), HIWORD(hotkeys[k]) ) ) { _key_name( HIWORD(hotkeys[k]), LOWORD(hotkeys[k]), key ); return FALSE; } else { UnregisterHotKey( __dlg, k ); } } return TRUE; }
static int _ecore_wince_hardware_keys_register(HWND window) { HINSTANCE core_dll; UnregisterFunc1Proc unregister_fct; int i; core_dll = LoadLibrary(L"coredll.dll"); if (!core_dll) { ERR("LoadLibrary() failed"); return 0; } unregister_fct = (UnregisterFunc1Proc)GetProcAddress(core_dll, L"UnregisterFunc1"); if (!unregister_fct) { ERR("GetProcAddress() failed"); FreeLibrary(core_dll); return 0; } for (i = 0xc1; i <= 0xcf; i++) { unregister_fct(MOD_WIN, i); RegisterHotKey(window, i, MOD_WIN, i); } FreeLibrary(core_dll); return 1; }
void ATMainWindow_c::DoRegisterHotKey() { #ifdef _WIN32 UnregisterHotKey( winId(), EZ_HOTKEY ); if ( m_bHotkeyEnabled ) { int iModifier = 0; int iKey = 0; if ( m_strHotkeyMod1 == "Ctrl" ) iModifier |= MOD_CONTROL; if ( m_strHotkeyMod1 == "Alt" ) iModifier |= MOD_ALT; if ( m_strHotkeyMod2 == "Shift" ) iModifier |= MOD_SHIFT; if ( !m_strHotkeyKey.isEmpty() ) { iKey = m_strHotkeyKey.toUpper().at( 0 ).toLatin1(); if ( iKey < 'A' || iKey > 'Z' ) iKey = 0; } if ( iModifier && iKey ) RegisterHotKey( winId(), EZ_HOTKEY, iModifier, iKey ); } #endif }
// assumes UnregisterHotKeys was called before static int RegisterHotKeys() { hMessageWindow = CreateWindowEx(0, _T("STATIC"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); SetWindowLongPtr(hMessageWindow, GWLP_WNDPROC, (LONG_PTR)MessageWndProc); int count = GetProfileCount(0, 0); for ( int i=0; i < count; i++ ) { if (!db_get_b(NULL, MODULENAME, OptName(i, SETTING_REGHOTKEY), 0)) continue; WORD wHotKey = db_get_w(NULL, MODULENAME, OptName(i, SETTING_HOTKEY), 0); hkInfo = ( HKINFO* )realloc(hkInfo, (hkiCount+1)*sizeof(HKINFO)); if (hkInfo == NULL) return -1; char atomname[255]; mir_snprintf(atomname, _countof(atomname), "StatusProfile_%d", i); hkInfo[hkiCount].id = GlobalAddAtomA(atomname); if (hkInfo[hkiCount].id == 0) continue; hkInfo[hkiCount].profile = i; hkiCount ++; RegisterHotKey(hMessageWindow, (int)hkInfo[hkiCount-1].id, GetFsModifiers(wHotKey), LOBYTE(wHotKey)); } if (hkiCount == 0) UnregisterHotKeys(); return 0; }
void CChatDlg::DlgInit() { RegisterHotKey(this->GetSafeHwnd(), nHotkey, MOD_CONTROL, VK_RETURN); //注册快捷键 CString strTitle = _T("信使服务 \\\\"); strTitle += m_strIP; SetWindowText(strTitle); }
BOOL CPaper::OnInitDialog() { CDialog::OnInitDialog(); m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); // TODO: 在此添加额外的初始化 m_Paper.InsertItem(0,"进程注入"); m_Paper.InsertItem(1,"进程信息"); m_Paper.InsertItem(2,"加壳工具"); m_Paper1.Create(IDD_RUNDLL32_DIALOG,this->GetDlgItem(IDC_TAB1)); m_Paper2.Create(IDD_TASK,this->GetDlgItem(IDC_TAB1)); m_Paper3.Create(IDD_PACK,this->GetDlgItem(IDC_TAB1)); CRect PageRect; m_Paper.GetClientRect(&PageRect); PageRect.top+=20; PageRect.bottom-=4; PageRect.left+=4; PageRect.right-=4; m_Paper1.MoveWindow(&PageRect); m_Paper2.MoveWindow(&PageRect); m_Paper3.MoveWindow(&PageRect); m_Paper1.ShowWindow(SW_SHOW); m_Paper2.ShowWindow(SW_HIDE); m_Paper3.ShowWindow(SW_HIDE); m_Paper1.SetFocus(); SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); CFlash flash; flash.DoModal(); RegisterHotKey(m_hWnd,0,NULL,VK_F7); menu.CreatePopupMenu(); menu.AppendMenu(MF_STRING,IDM_OPEN,"打开"); menu.AppendMenu(MF_STRING,IDM_EXIT,"退出"); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
/*! インスタンス ハンドルを保存して、メイン ウィンドウを作成します。 この関数で、グローバル変数でインスタンス ハンドルを保存し、 メイン プログラム ウィンドウを作成および表示します。 @param[in] hInstance インスタンスハンドル @param[in] nCmdShow 起動時の表示状態 */ BOOL InitInstance( HINSTANCE hInstance, int nCmdShow ) { HWND hWnd; INT xxx, yyy; RECT rect; BOOL bHotRslt; ghInst = hInstance; // グローバル変数にインスタンス処理を格納します。 // 設定ファイル位置確認 GetModuleFileName( hInstance, gatIniPath, MAX_PATH ); PathRemoveFileSpec( gatIniPath ); PathAppend( gatIniPath, INI_FILE ); // ここらで初期設定確保 gbClipSteal = InitParamValue( INIT_LOAD, VL_COLLECT_AON, 0 ); // コピペ保存・デフォは起動時OFF gGetMsgOn = InitParamValue( INIT_LOAD, VL_USE_BALLOON, 1 ); gbUniRadixHex = InitParamValue( INIT_LOAD, VL_UNIRADIX_HEX, 0 ); // 初期設定は Ctrl+Shift+C gbHotMod = InitParamValue( INIT_LOAD, VL_COLHOT_MODY, (MOD_CONTROL | MOD_SHIFT) ); gbHotVkey = InitParamValue( INIT_LOAD, VL_COLHOT_VKEY, VK_C ); hWnd = GetDesktopWindow( ); GetWindowRect( hWnd, &rect ); xxx = ( rect.right - WCL_WIDTH ) / 2; yyy = ( rect.bottom - WCL_HEIGHT ) / 2; hWnd = CreateWindowEx( WS_EX_TOOLWINDOW | WS_EX_APPWINDOW, gatWindowClass, gatTitle, WS_CAPTION | WS_POPUPWINDOW, xxx, yyy, WCL_WIDTH, WCL_HEIGHT, NULL, NULL, hInstance, NULL); if( !hWnd ){ return FALSE; } // タスクトレイがあぼ〜んしたときの再起動メッセージ番号を確保 grdTaskbarResetID = RegisterWindowMessage( TEXT("TaskbarCreated") ); // クリップボードチェーンに自分を登録 ghNextViewer = SetClipboardViewer( hWnd ); FileListViewInit( hWnd ); // リスト初期化 FileListViewGet( hWnd, 0, gatClipFile ); // 取り込みファイルを確保しておく FileTypeCheck( gatClipFile ); // ASTかそうでないかを確認 if( gGetMsgOn ){ Button_SetCheck( GetDlgItem(hWnd,IDB_CLIP_USE_BALLOON) , BST_CHECKED ); } if( gbUniRadixHex ){ Button_SetCheck( GetDlgItem(hWnd,IDB_CLIP_UNIRADIX_HEX) , BST_CHECKED ); } if( gbClipSteal ){ Button_SetCheck( GetDlgItem(hWnd,IDB_CLIP_STEAL_ACT_ON) , BST_CHECKED ); } TasktrayIconAdd( hWnd ); // とりあえず、Ctrl+Shift+C bHotRslt = RegisterHotKey( hWnd, IDHK_CLIPSTEAL_FILECHANGE, gbHotMod, gbHotVkey ); ShowWindow( hWnd, SW_HIDE ); // SW_HIDE return TRUE; }
void RegHotkey(MCONTACT hContact, HWND hwnd) { char szBuf[MAX_PATH] = { 0 }; DBVARIANT dbv; if (db_get_s(hContact, MODULE, "Hotkey", &dbv)) return; strncpy(szBuf, dbv.pszVal, MAX_PATH - 1); db_free(&dbv); if (szBuf[0] != '\0') { UINT nModifiers = 0; char chKey = 0; char szMod[2][20] = { 0 }; char szKey[20] = { 0 }; sscanf(szBuf, "%[^'+']+%[^'+']+%[^'+']", szMod[0], szMod[1], szKey); for (int i = 0; i < 2; i++) { if (0 == strncmp(szMod[i], "ALT", 19)) nModifiers = nModifiers | MOD_ALT; else if (0 == strncmp(szMod[i], "CTRL", 19)) nModifiers = nModifiers | MOD_CONTROL; else if (0 == strncmp(szMod[i], "SHIFT", 19)) nModifiers = nModifiers | MOD_SHIFT; } chKey = szKey[0]; RegisterHotKey(hwnd, (INT_PTR)hwnd, nModifiers, VkKeyScan(chKey)); } }
/*! メインのウインドウプロシージャ @param[in] hWnd 親ウインドウのハンドル @param[in] message ウインドウメッセージの識別番号 @param[in] wParam 追加の情報1 @param[in] lParam 追加の情報2 @retval 0 メッセージ処理済み @retval no0 ここでは処理せず次に回す */ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { HANDLE_MSG( hWnd, WM_CREATE, Cls_OnCreate ); // 画面の構成パーツを作る。ボタンとか HANDLE_MSG( hWnd, WM_PAINT, Cls_OnPaint ); // 画面の更新とか HANDLE_MSG( hWnd, WM_COMMAND, Cls_OnCommand ); // ボタン押されたとかのコマンド処理 HANDLE_MSG( hWnd, WM_DESTROY, Cls_OnDestroy ); // ソフト終了時の処理 HANDLE_MSG( hWnd, WM_HOTKEY, Cls_OnHotKey ); // HANDLE_MSG( hWnd, WM_CTLCOLORSTATIC, Cls_OnCtlColor ); HANDLE_MSG( hWnd, WM_DRAWCLIPBOARD, Cls_OnDrawClipboard ); // クリップボードに変更があったら HANDLE_MSG( hWnd, WM_CHANGECBCHAIN, Cls_OnChangeCBChain ); // クリップボードビューワチェインに変更があったら case WM_CLOSE: // 設定閉じるとき RegisterHotKey( hWnd, IDHK_CLIPSTEAL_FILECHANGE, gbHotMod, gbHotVkey ); // 登録し直し ShowWindow( hWnd, SW_HIDE ); return 0; case WMP_TRAYNOTIFYICON: // タスクトレイのアイコンがクリッコされたら TaskTrayIconEvent( hWnd, (UINT)wParam, (UINT)lParam ); return 0; default: if( grdTaskbarResetID == message ) // タスクトレイがあぼ〜んした時 { TasktrayIconAdd( hWnd ); // タスクトレイがあぼ〜んしたときのメッセージ。 return 0; // 登録し直し } break; } return DefWindowProc( hWnd, message, wParam, lParam ); }
//Производит регистрацию/антиригистрацию всех горячих клавиш указанного роутера. //i_register - если true, то регистрация, иначе антирегистрация bool HotKeysManager::RegisterOneRouter(CHotKeysToCmdRouter* ip_router, bool i_register) { bool result = true; bool is_command_exist = false; if (NULL==ip_router || NULL==ip_router->mp_OriginalWnd) { ASSERT(0); return false; } CHotKeysToCmdRouter::HotKeyMap::iterator it; for(it = ip_router->m_hot_key_map.begin(); it != ip_router->m_hot_key_map.end(); ++it) { if (!i_register) { if (UnregisterHotKey(ip_router->mp_OriginalWnd->m_hWnd, (*it).first)) result = false; } else { BOOL status = RegisterHotKey(ip_router->mp_OriginalWnd->m_hWnd, (*it).first, (*it).second.m_fsModifiers, (*it).second.m_vk); result = status ? true : false; } } return result; }