Keyboard hook (probably JNI realted) problem

I have written a C++ DLL to disable some specific function key. Then I wrote a Java application using JNI to call this DLL. The keyboard hook only works inside its function (that is from "void funx() {" to end of function "}" ). The keyboard hook no longer functions when DLL library function finish.
The DLL works perfectly fine when I can call the DLL library function from a C++ application. The keyboard hook disable some specfic key perfectly well (with the SetWindowsHookEx API).
Any help or suggestion are welcomed.
Thanks in advance for reading this post.

Hi wincoyu!
this isn't a reply, but a question :)
I'm working on a Java app running in bkground waiting a specific key to be pressed.Do you think i can use java methods to do this, and no DLLs ecc.?
If not, can you give me some tips for my work?
Thanks you, and excuse my bad english
Marco

Similar Messages

  • HT1338 I have an apple wired keyboard hooked up to my Mac mini. A while ago, the keyboard stopped working. I tried re plugging it in, and nothing's working. The "Bluetooth settings" keeps popping up, but I don't have Bluetooth, it's wired. Please help!

    I have an apple wired keyboard hooked up to my Mac mini. A while ago, the keyboard stopped working. I tried re plugging it in, and nothing's working. The "Bluetooth settings" keeps popping up, but I don't have Bluetooth, it's wired. Please help!

    System Preferences->BlueTooth and turn it off. Restart and see if that fixes the problem.

  • TS3048 My early 2009 Mac Pro does not connect via bluetooth to my sound bar or bluetooth mini speakers. Both my wireless keyboard and mouse have no problems connecting. What do I need to do to connect to external bluetooth devices?

    My early 2009 Mac Pro does not connect via bluetooth to my sound bar or bluetooth mini speakers. Both my wireless keyboard and mouse have no problems connecting. What do I need to do to connect to external bluetooth devices?

    I would always have a wired keyboard and mouse on hand (need not be expensive ... any cheap wired devices will work).  "Emergency recovery" procedures can activate features in random order, so the opportunity to select a recovery partition may pass before the wireless devices are recognized.
    That will let you select the "turn on Bluetooth" icon.

  • I keep getting this diologue box as I start up Firefox "Could not initialise the application's security component. The most probable cause is problems with files in your browser's profile directory. ... what should I do exactly?

    I keep getting the following dialogue box when I start Firefox " Could not initialise the application's security component. The most probable cause is problems with files in your browser's profile directory. Please check that this directory has no read/write restrictions." I am not sure how to find or change the profile directory. I have gone to the Options: General: Save files to ...box but it wont allow me to browse to another file and the box remains blank. ideas please!

    See [[Could not initialize the browser security component]]
    Continue here: [/questions/780717]

  • Why do I get an alert saying "Could not initialise the application's security component. The most probable cause is problems with files in your browser's profile directory. How can I solve it??

    The full alert is " Could not initialise the application's security component. The most probable cause is problems with files in your browser's profile directory. Please check that this directory has no read/write restrictions and your hard drive is not full or close to full. It is recommended that you exit the browser and fix the problem. If you continue to use this browser session, you might see incorrect browser behaviour when accessing security features."
    This is just started three/four days ago. I need assistance quickly as I can't access any secure sites e.g bank accounts/homepage etc.

    See [[Could not initialize the browser security component]]

  • This is probably an overscan problem, but..

    Hey guys/girls,
    I'm a fairly new video (80gb) iPod owner and I have some questions about tv output.
    I've been trying to output some subtitled avi files to my television, and the subtitles are getting cut off on the sides and some on the bottom.
    The best result I got was cropping a 16:9 format .h264 640x352 file with 14 pixels on the top and bottom, then all of the subs were visible, but the characters were stretched and squatty (as expected, since I do not have a 16:9 television).
    The video files in question are in 640x480 resolution divx format, and if displayed using another media player on the television (such as one for the ps2 or xbox media center), they display fine with subtitles intact.
    The fact that they are getting "blown up" over the screen size of the tv, even at 640x480 tells me that this is probably an overscan problem, but does anyone have any suggestions on how to get these videos to display properly on my tv?
    My next thought was to try cropping the sides of a 16:9 format to make things look closer to 4:3 with borders on all sides, as that would be preferable to having the subtitles cut off.
    Thanks in advance

    hi, yeh i had the same problem as u, it would say that the usb is unknown, and yeh it is because u are using the wrong cable.
    i had tried, for instance dwnloading the driver n stuff, eventually i found out it was because its the wrong cable, u see i had a previous cable for an old nokia phone, and i mistakly used that instead of the new one. once i plugged in the new cable although they both luked the same, it wrked. u sud luk up the type of cable ur phone takes.
    hope this helps.

  • My camera and safari disappeared. I also have a passcode that I must enter and I can't remove it. These areas are grayed-out in settings as well.apple support said probably a software problem. But I didn't want to pay the $70 so I'll try this support

    My camera and safari disappeared. I also have a passcode that I must enter and I can't remove it. These areas are grayed-out in settings as well.apple support said probably a software problem. But I didn't want to pay the $70 so I'll try this support

    For forgotton passcode
    http://support.apple.com/kb/HT1212
    For missing icons, these must be somewhere in some folder. if you can't find
    Use Settings > General > Reset > Reset Home Screen Layout.

  • HT4528 Howdy.  I keep getting a message stating that my apple ID has been disabled.  I recently contacted my CC company, AMEX, for several fradulent iTune charges, which is probably where the problem first originated.  How can I resolve this issue?

    Howdy.  I keep getting a message stating that my apple ID has been disabled.  I recently contacted my CC company, AMEX, for several fradulent iTune charges, which is probably where the problem first originated.  How can I resolve this issue?

    I had to dispute several unauthorized charges to itunes. My apple id was disabled after that. I followed jarnoldus's (older post) advice and it worked. Im duplicating his entry here with a few modifications. I hope this works for you.
    1. Go to https://getsupport.apple.com
    2. Choose your product (mine was ipad)
    3. Click the "iTunes, App Store or iBooks" icon
    4. Click "Apple ID account security"
    5. Type in "apple id has been disabled"
    6. Choose your country (mine was US)
    7. Choose the "talk to apple support now" option
    8. Provide the info they request (name, email, phone number)
    9. They will call you right away.
    Explain your apple id has been disabled. The rep will connect you to an iTunes rep. He/she will look up your account. You will be required to answer your 3 security questions. You MUST get a minimum of 2 correct. If you succeed they will enable your id. Good luck!

  • Keyboard hooking, UWM_MOUSEMOVE_MSG

    Hi Igor
    The following program is the DLL part of the keyboard hooking.
    The one I don't understand is how in [Q1] UWM_MOUSEMOVE_MSG is
    defined as _T("UWM_MOUSEMOVE_MSG-44E531B1_14D3_11d5_A025_006067718D04").
    Is it something I just have to remember? [Q1] is used in [Q2].
    Regards
    Chong
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    #include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <Windows.h>
    #include <WinUser.h>
    //#define _COMPILING_44E531B1_14D3_11d5_A025_006067718D04
    //#include "MouseHook.h"
    #include <tchar.h>
    #include <string.h>
    [Q1] #define UWM_MOUSEMOVE_MSG _T("UWM_MOUSEMOVE_MSG-44E531B1_14D3_11d5_A025_006067718D04")//_T(.....)
    HINSTANCE hInst;
    UINT UWM_MOUSEMOVE;
    HHOOK hook;
    HWND hWndServer = NULL;
    int gChong;
    FILE *fp;
    static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam);
    BOOL APIENTRY DllMain( HINSTANCE hInstance,
                           DWORD  Reason,
                           LPVOID Reserved
    *                                 clearMyHook
    * Inputs:
    *       HWND hWnd: Window hook
    * Result: BOOL
    *       TRUE if successful
    * FALSE if error
    * Effect:
    *       Removes the hook that has been set
    __declspec(dllexport) BOOL clearMyHook(HWND hWnd)
         if(hWnd != hWndServer || hWnd == NULL)
         return FALSE;
         BOOL unhooked = UnhookWindowsHookEx(hook);
         if(unhooked)
          hWndServer = NULL;
         return unhooked;
    } // clearMyHook
    *                                 setMyHook
    * Inputs:
    *       HWND hWnd: Window to notify
    * Result: BOOL
    *       TRUE if successful
    * FALSE if error
    * Effect:
    *       Sets the hook
    __declspec(dllexport) BOOL setMyHook(HWND &hWnd)
        printf("gChong = %d\n",gChong);//getchar();
        if(hWndServer != NULL)
           return FALSE; // already hooked!
         printf("GetModuleHandle(1): %d\n",GetModuleHandle(L"ahookDLL.dll"));
        //GetModuleHandle obtains a handle to a module loaded into
        //the calling process. In other examples. PCspeed.exe is not so
        //loaded - it is started as a separate process, by _spawnlp.
        hook = SetWindowsHookEx(WH_GETMESSAGE,
          (HOOKPROC)msghook,
         GetModuleHandle(L"ahookDLL.dll"),// hInst,
          0);
       if (hook==NULL){printf("error: %d\n",GetLastError()); 
          char dest[20];
          if(fopen_s(&fp,"jin.txt","w")==0){//successful. fp!=NULL.
              _itoa_s(GetLastError(),dest,sizeof(dest),10);
              fwrite(dest,sizeof(char),20, fp);
              fclose(fp);
       if(hook != NULL)
       { /* success */
          hWndServer = hWnd;
          printf("GetModuleHandle(2): %d\n",GetModuleHandle(L"ahookDLL.dll"));
          DllMain(GetModuleHandle(L"ahookDLL.dll"), DLL_PROCESS_ATTACH, NULL);
          return TRUE;
       } /* success */
       return FALSE; // failed to set hook
    } // setMyHook
    BOOL APIENTRY DllMain( HINSTANCE hInstance,
                           DWORD  Reason,
                           LPVOID Reserved
        switch(Reason)
        { /* reason */
         case DLL_PROCESS_ATTACH:
           printf("GetModuleHandle(3): %d\n",GetModuleHandle(L"ahookDLL.dll"));
           hInst = hInstance;
    [Q2] UWM_MOUSEMOVE = RegisterWindowMessage(UWM_MOUSEMOVE_MSG);
           return TRUE;
         case DLL_PROCESS_DETACH:
           if(hWndServer != NULL)
           clearMyHook(hWndServer);
           return TRUE;
        } /* reason */
        return TRUE;
    *                                   msghook
    * Inputs:
    *       int nCode: Code value
    * WPARAM wParam:
    * LPARAM lParam:
    * Result: LRESULT
    *       Either 0 or the result of CallNextHookEx
    * Effect:
    *       Hook processing function. If the message is a mouse-move message,
    *     posts the coordinates to the parent window
    static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam)
         static int x=0;
         if(nCode < 0)
         { /* pass it on */
            CallNextHookEx(hook, nCode, wParam, lParam);
            return 0;
         /* pass it on */
         LPMSG msg = (LPMSG)lParam;
         if(msg->message == WM_MOUSEMOVE ||
           msg->message == WM_NCMOUSEMOVE){
        //PostMessage(hWndServer, WM_LBUTTONUP, 0, 0);
            PostMessage(hWndServer, UWM_MOUSEMOVE, 0, 0);
            HDC hdc = GetDC(hWndServer);
            TextOut(hdc, x, x, L"msghook", 7); x=x+15;
            ReleaseDC(hWndServer, hdc);
           printf("msghook\n");
           if (fopen_s(&fp,"chong.txt","w")==0){//successful. fp!=NULL.
              fprintf_s( fp, "%s%c", "This is chong kim",'\n' );
              fclose(fp);
       if(msg->message == WM_CHAR){
          HDC hdc;
          wchar_t vkCode[8];//wchar_t is 2 bytes long
          static int y=0;
         if( memcpy_s(vkCode,4,&(msg->wParam),4)!=0){//failure. memcpy byte by byte.
             printf("memcpy_s failed\n");getchar();exit(0);
             //return CallNextHookEx(hook, nCode, wParam, lParam);
        hdc = GetDC(hWndServer);
        //TextOut(hdc, 10+y, 115,vkCode, 2);//Prints 2 wchar_t chars(4 bytes in total),
                                        //i.e. vkCode[0] and vkCode[1].
        TextOut(hdc, 10+y, 115, vkCode, 1);//Prints vkCode[0].
        y=y+15;
        ReleaseDC(hWndServer, hdc);
      return CallNextHookEx(hook, nCode, wParam, lParam);
    } // msghook
    Regards
    Chong

    On 1/27/2015 8:29 AM, "chong kyong kim" wrote:
    The one I don't understand is how in [Q1] UWM_MOUSEMOVE_MSG is
    defined as _T("UWM_MOUSEMOVE_MSG-44E531B1_14D3_11d5_A025_006067718D04").
    It just needs to be a unique string - the actual value doesn't matter. Apparently, the author of  the sample you are working off has generated a GUID in order to guarantee uniqueness. You should be using some other string, not the one used in the
    sample (otherwise, your program may conflict with another program whose author blindly copied the same sample).
    Igor Tandetnik

  • Keyboard function cannot work (probably kbdmgr.exe problem)

    i have a problem. when i start up with windows xp, it will show the warning message like this, "boot camp manager has encountered a problem..".
    and this is the error report:
    error signature
    AppName : kbdmgr.exe AppVer: 2.0.0.9 ModName: unknown
    ModVer: 0.0.0.0 Offset: 00980280
    this make my keyboard function (F3-F5 for sound, F1-F2 for brightness) does not work.
    can you help me? thanks..

    For anyone else with the same problem - I had mouse keys turned on in the Universal Access preferences - turned it off and everything works as expected now.
    Still, maybe Apple could have included some sort of dialog about this in the Keyboard Software installer?

  • Lower Level Keyboard Hook problem C++

    Hi MSDN,
    I am working on a Very Simple Low Level Hook Program in which the Program 'cout<<' some thing when a Letter is pressed but the problem is that the Hook doesn't work. The Code: 
    #include<Windows.h>
    #include<iostream>
    using namespace std;
    HHOOK hHock = NULL;
    LRESULT CALLBACK MyLowLevelHook ( int nCode , WPARAM wParam , LPARAM lParam)
    cout<<"Key is Pressed";
    return CallNextHookEx(hHock , nCode ,wParam , lParam);
    int main()
    hHock = SetWindowsHookEx(WH_KEYBOARD_LL , MyLowLevelHook , NULL,NULL);
    cin.get();

    Yes sure:
    Okay First we want to make a Low Level Hook right ...
    So lets first set up a Global Hook ...
    Like this:
    #include<Windows.h>
    #include <stdio.h>
    HHOOK hHock = NULL;
    int main()
    return 0;
    Then we must set up the Windows hook for this we must do this : 
    #include<Windows.h>
    #include <stdio.h>
    HHOOK hHock = NULL;
    int main()
    hHock = SetWindowsHookEx(WH_MOUSE_LL, MyLowLevelHook , NULL,NULL);
    So now we got it set up but 'MyLowLevelHook' is undefined and now we must define it like this:
    #include<Windows.h>
    #include <stdio.h>
    HHOOK hHock = NULL;
    LRESULT CALLBACK MyLowLevelHook ( int nCode , WPARAM wParam , LPARAM lParam)
    printf("You have Moved the Mouse");
    return CallNextHookEx(hHock , nCode ,wParam , lParam); //This is very Important since we tell the Windows that send me the next// Message so that we do not cause Error and stuff in Windows OS .}
    int main()
    hHock=SetWindowsHookEx(WH_MOUSE_LL,MyLowLevelHook,
    NULL,NULL);
    We have Finally Set the Hook but we need to put a Message Loop as Igor said ....
    Now  we should add the Message loop like this :
    #include<Windows.h>
    #include <stdio.h>
    HHOOK hHock = NULL;
    LRESULT CALLBACK MyLowLevelHook ( int nCode , WPARAM wParam , LPARAM lParam)
    printf("_a_");
    return CallNextHookEx(hHock , nCode ,wParam , lParam);
    int main()
    MSG msg;
    hHock = SetWindowsHookEx(WH_MOUSE_LL, MyLowLevelHook , NULL,NULL);
    while(!GetMessage(&msg, NULL, NULL, NULL)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    UnhookWindowsHookEx(hHock);
    Yes  the code above is a Simple Hook. Please don't delete the Message Loop else your Computer can freeze and you have to restart it again and none of us want that.

  • Mouse hook from JNI doesn't work

    Hello
    i am trying to register windows mouse hook(WH_MOUSE) from java using jni. (windows vista x64)
    all is fine when i register hook from c++ application. strange things start to happen when the hook is registered inside jni.
    i implemented a hook proc in 32bit dll, when it is injected into 32bit processes it looks ok, but 64bit applications stop responding. 64bit dll injected into all windows makes 32bit apps inactive for any mouse inputs, similar as in first scenario.
    there are no problems with WH_KEYBOARD or WH_SHELL hooks
    here is the code:
    //dll loaded in jni function
    extern "C" __declspec(dllexport) LRESULT HookMouseProc(int nCode,WPARAM wParam,LPARAM lParam)
         if(nCode<0)
              return CallNextHookEx(NULL, nCode, wParam, lParam);
         if(wParam==WM_RBUTTONDOWN && nCode==HC_ACTION)
              AfxMessageBox("inside mouse proc");
         return CallNextHookEx(NULL, nCode, wParam, lParam);
    //jni dll
    extern "C" JNIEXPORT jboolean JNICALL Java_winHook_WinHookUtil_setMouseHook(JNIEnv *env, jobject jObject)
         HMODULE hModule=LoadLibrary("WinHook32.dll");
         void* fnt=GetProcAddress(hModule, "HookMouseProc");
         g_hookMouse=SetWindowsHookEx(WH_MOUSE, (HOOKPROC)fnt, hModule, NULL);
         return JNI_TRUE;
    i have no idea what is wrong. please help.
    Edited by: user3530356 on 2010-10-03 16:19

    all is fine when i register hook from c++ application.What about when you register the hook from a DLL? A 32-bit DLL? a 64-bit DLL?
    This is clearly a 32/64 issue. Not a JNI issue.

  • Probably a battery problem...

    I got my iMac G3 in the summer of '00 when I was first going to college. I'm going back to school now and have been having some problems over the past few months. Here's what's been happening.
    Over Thanksgiving break, my dorm wanted me to have everything unplugged, so I unplugged my computer. A week later when I came back, I plugged my computer back in, but the computer would not turn on. That is to say, I would press the power button, and for a moment, the power light would turn on, but just before the computer would chime, the computer would turn off. Pushing the power button would not work; I would have to unplug the computer and replug it in before I could push the power button. Finally after I let it sit for a while, the computer finally worked. But it had been about 10 hours.
    A similar incident happened over winter break. I ended up taking my computer home, not wanting a repeat of what had happened during Thanksgiving break. But when I got my computer home, the same problem occurred. This time, it took about four days before I could get it turned on. When I brought the computer back to school at the end of break, the same problem occurred again; I could not turn on my computer for about three days.
    My guess is that the battery inside the computer (at least, I have been told that there is an internal battery) is probably bad and I need to get it replaced. I saw that there was another comment on this forum that probably was the same problem, but I didn't really see a way to solve it. If it is a matter of a bad battery, how can I fix it? Do I need to take it somewhere to get it repaired? Is it a fix that I can do myself? Is it perhaps something else I'm missing? Hook a brother up.

    It does sound like a battery problem.
    Battery info. at Mac internal batteries - link.
    Take-apart pictoral here - link.
    The tray-load CD drive machines are a little harder to get into than the later slot-loaders, but if you are careful, it's easily a repair that an owner can do.
    David

  • JNI & thread problem

    Folks,
    I am using JNI to access WIA (Windows Image Acquisition) functionality under MS Windows XP. WIA consists of a bunch of COM interfaces. I have several native functions in a single dll, with a limited number of static variables stored in the dll between calls. This all works fine as long as long as the calls occur from the same java thread, but not if a new thread is created for some of the calls. I.e., this works:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    but this does not:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    (new Thread() {
    public void run() {               
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    }).start();
    Here, initializeWIA() and transferJPGNative() are the native methods. What happens in the second case is that transferJPGNative fails in one of the COM methods (not the first COM method it calls). The COM method returns an HRESULT indicating an error (509) which I can't find using any of the usual MS error look-up mechanisms. (Admittedly I am not the world's greatest Windows programmer...)
    Anyway, any suggestions would be much appreciated. I have found some issues regarding JNI and threads in this forum's archives, but none of them seem to apply to quite this situation.

    As a guess this is just a windows threading problem.
    And with COM you have to do things differently (I believe) if there is more than one thread. You might not even be allowed to do it with for that particular API.
    It could also be that you are initializing things more than once. Or you need to initialize twice (two handles.)
    At any rate you could always fix it by making the java code only allow calls for a single thread.

  • Compaq CQ60-615Dx keyboard displays wrong key. Problem is only with the 2 w s and x keys.

    Problem is only with 2 w s x keys.  Tried updating BIOS and num lock suggestion.  Looking for instruction for removing keyboard or any suggestions

    Hi,
    This may well be a Hardware issue with the keyboard itself, but re-seating the ribbon connection to the Motherboad and the keyboard is certainly worth trying.
    The procedure to remove the keyboard is detailed starting on Page 56 of your Maintenance & Service Guide.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

Maybe you are looking for

  • Item Number not getting copied from Delivery to Invoice

    Dear Experts I am having a problem where Item Number in Delivery is 10 and in Invoice it is 11. The item number is  not getting copied from Delivery to Invoice. I have checked the copy control option and copy item number is checked. Please advise

  • YEAR function in BMM

    Hi everybody! I am facing strange problem in OBIEE (server version 11.1.1.6). Adding logical column to fact table, that is derived from existing column using following expression: FILTER("TT#1"."FACT"."TICKET_NUMBER" USING  EXTRACT( YEAR  FROM "TT#1"

  • Are all external FW drives used for Time Machine more prone to fail?

    Within a period of just several months, I've seen three different external FW drives used for time Machine in three different locations fail terminally.  They were different brands (Seagate, OWC and a nondescript generic from Fry's). Is there somethi

  • What happened to tradewinds legends?

    What happened to tradewinds legends for iPad at app store?  I had it on my first iPad two years ago, but when I transferred all apps to my new iPad it disappeared.  It is no longer offered at app store.

  • How to make a time based image transition using CSS?

    Hi I want to make an image in a DIV morph into another (in the same DIV) and then back again every ten or 20 seconds, but I want the transition to be smooth. . I was wondering if there is a simple CSS way of doing this, rather than making an animated