[amirus] RUS

  • From: Vovka <jvovka@xxxxxxxxx>
  • To: amirus@xxxxxxxxxxxxx
  • Date: Sat, 04 Jan 2003 00:03:30 +0300

Hello,

Вот посмотрите:
все достаточно просто.
может я что-то и напутал, но  IMHO это самый системный из системных способов 
навешивания hotkey. :-)
<tsb>
#include<exec/types.h>
#include<exec/memory.h>
#include<utility/hooks.h>
#include<utility/tagitem.h>
#include<libraries/commodities.h>
#include<libraries/mui.h>
#include<libraries/asl.h> 

#include<proto/exec.h>
#include<proto/muimaster.h>
#include<proto/intuition.h>
#include<proto/commodities.h>
#include<proto/dos.h>
#include<clib/alib_protos.h>
#include<clib/alib_stdio_protos.h>

struct Library *MUIMasterBase, *CxBase;
#define EVT_HOTKEY 1

ULONG HotKeyFunc(register __a2  Object *obj,register __a1 CxMsg *msg)
{
  ULONG msgid, msgtype;

  msgid = CxMsgID(msg);
  msgtype = CxMsgType(msg);
  if(msgtype==CXM_IEVENT)
  {
    if(msgid==EVT_HOTKEY)
    {
      Printf("HotKey!\nLet's change keymap!\n");
    };
  };
  return(0);
};


void main()
{

  ULONG sigs = 0;
  APTR app,win;

  struct Hook hotkey_hook={    NULL,    NULL,    (ULONG (*)(void))&HotKeyFunc, 
NULL, NULL};

  MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN-1);
  CxBase = OpenLibrary("commodities.library", 37L);

    app    =    ApplicationObject,
    MUIA_Application_Title      , "KeyMapper",
    MUIA_Application_Version    , "0.01",
    MUIA_Application_Copyright  , "(C)2002 AmiRUS Club",
    MUIA_Application_Author     , "AmiRus Club",
    MUIA_Application_Description, "Keymap exchanger",
    MUIA_Application_Base       , "KEYMAPPER",
    MUIA_Application_SingleTask , TRUE,
  MUIA_Application_BrokerHook , &hotkey_hook,
    SubWindow, win=WindowObject,
    MUIA_Window_Title, "KeyMapper",
    WindowContents,
      VGroup,
          Child, PopstringObject, 
                    MUIA_Popstring_Button, PopButton(MUII_PopFile),
                    MUIA_Popstring_String, StringObject, StringFrame,
                MUIA_String_Contents, "#?.keymap",
                    End,
                End,
                Child, VGroup, GroupFrame,
          MUIA_FrameTitle, "Indication",
                Child, HGroup, 
                 Child, CheckMark(FALSE), 
               Child, Label("Title"), 
               Child, RectangleObject, End,
                End,
                Child, HGroup, 
                 Child, CheckMark(FALSE), 
               Child, Label("Sprite"), 
               Child, RectangleObject, End,
                End,
                Child, HGroup, 
                 Child, CheckMark(FALSE), 
               Child, Label("PowerLed"), 
               Child, RectangleObject, End,
                End,
              End,
            End,
    End,
    End;

    if(app)
    { 
*/* вот тут мы и навешиваем кнопку к другим событиям MUI */*
      CxObj *broker, *filter, *sender, *translate;
      MsgPort *broker_mp;

      GetAttr(MUIA_Application_Broker, app, (ULONG *)&broker);
      GetAttr(MUIA_Application_BrokerPort, app, (ULONG *)&broker_mp);
      filter = CxFilter(*"rawkey rcommand space"*);
      sender = CxSender(broker_mp, EVT_HOTKEY);
      translate = CxTranslate(NULL);
      AttachCxObj(broker, filter);
      AttachCxObj(filter, sender);
      AttachCxObj(filter, translate);

      DoMethod((Object *)win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
        app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);

      SetAttrs(win,MUIA_Window_Open,TRUE);

       while (DoMethod((Object *)app,MUIM_Application_NewInput,&sigs) != 
MUIV_Application_ReturnID_Quit)
      {
        if (sigs)
        {
          sigs = Wait(sigs | SIGBREAKF_CTRL_C);
          if(sigs & SIGBREAKF_CTRL_C) break;
        }
      };

      SetAttrs(win,MUIA_Window_Open,FALSE);

      MUI_DisposeObject((Object *)app);
    };
    
  if(CxBase) CloseLibrary(CxBase);
  if(MUIMasterBase) CloseLibrary(MUIMasterBase);
};
<tsb>
так что смотрите....
надо теперь рахобраться, как переключать раскладки в консоле.
спать хочется... завтра продолжу.

<sb>
Bye! 
Waiting to reply, Vovka.


Other related posts: