Manjish Posted February 17, 2009 Share Posted February 17, 2009 (edited) Guys here's a c++ script i wish to convert to autoit.. i have never worked with c++.. so don't know what's what.. Really will appreciate some help.. expandcollapse popup//////////////////////////////////////////////////////////////// // MSDN Magazine September 2002 // If this code works, it was written by Paul DiLascia. // If not, I don't know who wrote it. // Compiles with Visual Studio 6.0 and Visual Studio .NET on Windows XP. // // This file implements the low-level keyboard hook that traps the task // keys. // #define _WIN32_WINNT 0x0500 // for KBDLLHOOKSTRUCT #include <afxwin.h> // MFC core and standard components #define DLLEXPORT __declspec(dllexport) ////////////////// // App (DLL) object // class CTaskKeyHookDll : public CWinApp { public: CTaskKeyHookDll() { } ~CTaskKeyHookDll() { } } MyDll; //////////////// // The section is SHARED among all instances of this DLL. // A low-level keyboard hook is always a system-wide hook. // #pragma data_seg (".mydata") HHOOK g_hHookKbdLL = NULL; // hook handle BOOL g_bBeep = FALSE; // beep on illegal key #pragma data_seg () #pragma comment(linker, "/SECTION:.mydata,RWS") // tell linker: make it // shared ///////////////// // Low-level keyboard hook: // Trap task-switching keys by returning without passing along. // LRESULT CALLBACK MyTaskKeyHookLL(int nCode, WPARAM wp, LPARAM lp) { KBDLLHOOKSTRUCT *pkh = (KBDLLHOOKSTRUCT *) lp; if (nCode==HC_ACTION) { BOOL bCtrlKeyDown = GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1); if ((pkh->vkCode==VK_ESCAPE && bCtrlKeyDown) || // Ctrl+Esc // Alt+TAB (pkh->vkCode==VK_TAB && pkh->flags & LLKHF_ALTDOWN) || // Alt+Esc (pkh->vkCode==VK_ESCAPE && pkh->flags & LLKHF_ALTDOWN)|| (pkh->vkCode==VK_LWIN || pkh->vkCode==VK_RWIN)) { // Start Menu if (g_bBeep && (wp==WM_SYSKEYDOWN||wp==WM_KEYDOWN)) MessageBeep(0); // only beep on downstroke if requested return 1; // gobble it: go directly to jail, do not pass go } } return CallNextHookEx(g_hHookKbdLL, nCode, wp, lp); } ////////////////// // Are task keys disabledie, is hook installed? // Note: This assumes there's no other hook that does the same thing! // DLLEXPORT BOOL AreTaskKeysDisabled() { return g_hHookKbdLL != NULL; } ////////////////// // Disable task keys: install low-level kbd hook. // Return whether currently disabled or not. // DLLEXPORT BOOL DisableTaskKeys(BOOL bDisable, BOOL bBeep) { if (bDisable) { if (!g_hHookKbdLL) { g_hHookKbdLL = SetWindowsHookEx(WH_KEYBOARD_LL, MyTaskKeyHookLL, MyDll.m_hInstance, 0); } } else if (g_hHookKbdLL != NULL) { UnhookWindowsHookEx(g_hHookKbdLL); g_hHookKbdLL = NULL; } g_bBeep = bBeep; return AreTaskKeysDisabled(); } Edited February 17, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
BrettF Posted February 17, 2009 Share Posted February 17, 2009 I'd search the forums for CallNextHookEx, because I'm pretty sure you will find it. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Ascend4nt Posted February 17, 2009 Share Posted February 17, 2009 That'd be C++ code, not VB Script.Anyhoo, keyboard hook code can be found here: http://www.autoitscript.com/forum/index.php?showtopic=55694 My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs |Â Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) |Â Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Manjish Posted February 17, 2009 Author Share Posted February 17, 2009 Thanks for correcting me, ascendant.. i looked at larry's script.. it is a gr8 hook.. But my problem is different.. I need to disable any keyboard shortcuts, using this script.. like windows+d alt+tab.. etc.. if ((pkh->vkCode==VK_ESCAPE && bCtrlKeyDown) || // Ctrl+Esc // Alt+TAB (pkh->vkCode==VK_TAB && pkh->flags & LLKHF_ALTDOWN) || // Alt+Esc (pkh->vkCode==VK_ESCAPE && pkh->flags & LLKHF_ALTDOWN)|| (pkh->vkCode==VK_LWIN || pkh->vkCode==VK_RWIN)) { // Start Menu if (g_bBeep && (wp==WM_SYSKEYDOWN||wp==WM_KEYDOWN)) MessageBeep(0); // only beep on downstroke if requested return 1; // gobble it: go directly to jail, do not pass go This section here does all that.. I need to add it somehow into Larry's script.. will appreciate some help.. thanks.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Manjish Posted February 17, 2009 Author Share Posted February 17, 2009 Can someone help me convert this c++ bit into autoit.. I tried his return 1.. but unable to achieve the desired result.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
LarryDalooza Posted February 17, 2009 Share Posted February 17, 2009 It looks as if, to be a "Global" or "System" hook... you need to get this code into a DLL. Otherwise you cannot "gobble". I am not into gobble hooks or much of any C programming anymore... Lar. AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now