Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Problem with windows hotkeys

  1. #1

    Problem with windows hotkeys

    Hi

    I have a problem with the windows hotkeys.
    When i press F10, my game freezes because F10 activates the menu bar and the app loses focus.
    When i press Alt, the same thing happens.
    I am sure there are more hotkeys, which do things i don't want.

    What is the best way to disable these hotkeys?? :?
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    Problem with windows hotkeys

    I had same problem, so i went and checked if alt key gave any special messages, and came up with this solution in message loop:

    Code:
        // wm_syskey messages are filtered to prevent app freeze and
        // confuse player when he presses the ALT key. this also redirects
        // system key codes into our key array and enables us to actually
        // even capture these keypresses ( FYI alt key is vk_menu. )
    
    
        WM_SYSKEYDOWN:
        begin
          ProcessKeyDown(wparam, lparam);
          Result := 0;
        end;
        WM_SYSKEYUP:
        begin
          ProcessKeyUp(wparam, lparam);
          Result := 0;
        end;
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #3

    Problem with windows hotkeys

    It doesn't compile ProcessKeyDown is an undeclared identifier.

    in which unit is this it defined
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4

    Problem with windows hotkeys

    Quote Originally Posted by chronozphere
    It doesn't compile ProcessKeyDown is an undeclared identifier.

    in which unit is this it defined
    I think you have to declare it yourself

    BTW, I have a related questions. I hide the mouse cursor when I get a WM_SETFOCUS, but I want to show it again with WM_KILLFOCUS... but ShowCursor(True) doesn't seem to work when receiving that message, probably because the focus is already lost and ShowCursor() doesn't allow to tell which window handle I'm refering to. What can I do?

  5. #5

    Problem with windows hotkeys

    Sorry but i dont know how i must declare it. :?
    I do not recieve the input using messages. i use Directinput. so i dont know what those methods must do.

    Just "Result := 0;" isn't enough to fix the problem. Something else must be done.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  6. #6

    Problem with windows hotkeys

    Quote Originally Posted by chronozphere
    Sorry but i dont know how i must declare it. :?
    I do not recieve the input using messages. i use Directinput. so i dont know what those methods must do.

    Just "Result := 0;" isn't enough to fix the problem. Something else must be done.
    The princip is same, just put them into a delphi-special-wm-handling-functions message function into the form object in the unit.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  7. #7

    Problem with windows hotkeys

    I'm just getting out from those problems... DirectInput is not very compatible with the system input. :?

    You could do it in 2 ways:

    1. Capture messages in a normal VCL application, as suggested by Delfi, or

    2. Make your own window processing loop in a formless application.

    If you follow the first path, first learn about capturing and processing messages with a TForm:

    http://www.informit.com/articles/art...&seqNum=1&rl=1

    If you follow the second path, read this tutorial about creating a formless app:

    http://delphi.about.com/od/windowssh.../apicourse.htm

  8. #8

    Problem with windows hotkeys

    It works.. i have written the following message handler:

    [pascal]
    function TBF_CustomEngine.WndProc(hWnd,Msg,wParam,lParam:In teger): integer;
    begin
    case Msg of
    WM_ACTIVATEAPP : begin
    fFocus := Boolean(wParam);
    if fFocus then
    begin
    //has focus
    //Log('>>>Application activated');
    ShowCursor(false);
    end else begin
    //has no focus
    //Log('>>>Application deactivated');
    ShowCursor(true);
    end;
    end;

    WM_TIMER: begin
    //FPS update only when game has focus
    fUpdateFPS := true;
    end;

    WM_CLOSE: begin
    {WM_CLOSE quit's rendering loop
    all resources and devices will be destroyed in
    BF_Core's destructor wich is called when BF_Core.Run ended}
    PostQuitMessage(0);
    Exit;
    end;
    WM_SYSKEYDOWN: begin
    //ProcessKeyDown(wparam, lparam);
    Result := 0;
    Exit;
    end;
    WM_SYSKEYUP: begin
    //ProcessKeyUp(wparam, lparam);
    Result := 0;
    Exit;
    end;
    end;

    Result := DefWindowProc(hWnd,Msg,wParam,lParam);
    end;
    [/pascal]

    I had to add the "exit;" statements because else the "defwindowProc" would be executed anyway.

    Thanx for your help
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  9. #9

    Problem with windows hotkeys

    Is that WndProc() a class method? How do you declare it in the class to be called correctly? And how do you assign it to lpfnWndProc when creating the window class?

    EDIT: Anyway, maybe it's a VCL event, so it doesn't apply to formless apps.

  10. #10

    Problem with windows hotkeys

    Quote Originally Posted by cronodragon
    Is that WndProc() a class method? How do you declare it in the class to be called correctly? And how do you assign it to lpfnWndProc when creating the window class?

    EDIT: Anyway, maybe it's a VCL event, so it doesn't apply to formless apps.
    yup, vcl tricks here

    something similar to this:

    Code:
    type
      TForm1 = class(TForm)
        procedure WMRecv(var Message: TMessage); message WM_RECV;
    and the TForm1.WMRecv will be called when the vcl's message loop goes around and detects it.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •