Subversion Repositories Kolibri OS

Rev

Rev 1900 | Rev 3628 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;   MyKey. Version 0.2.
  3. ;
  4. ;   Author:         Asper
  5. ;   Date of issue:  29.12.2009
  6. ;   Compiler:       FASM
  7. ;   Target:         KolibriOS
  8. ;
  9.  
  10. use32
  11.         org     0x0
  12.  
  13.         db      'MENUET01'      ; 8 byte id
  14.         dd      38              ; required os
  15.         dd      STARTAPP        ; program start
  16.         dd      I_END           ; program image size
  17.         dd      0x1000000       ; required amount of memory
  18.         dd      0x1000000       ; stack heap
  19.         dd      0x0
  20.         dd      app_path
  21.  
  22. include 'ASPAPI.INC'
  23. include 'string.inc'
  24. include 'macros.inc'
  25. include 'editbox_ex.mac'
  26. include 'load_lib.mac'
  27. include '../../../dll.inc'
  28.  
  29. include 'debug.inc'
  30. DEBUG    equ 0;1
  31.  
  32. N_KEYCOLOR    equ 0x00EEEEEE ; Normal button color
  33. C_KEYCOLOR    equ 0x00CBE1E1 ; Control button color
  34. A_KEYCOLOR    equ 0x00FF6400;258778 ; Active button color
  35. C_TEXTCOLOR   equ 0x80000000 ; Button caption color
  36. CA_TEXTCOLOR  equ 0x80FFFFFF ; Active button caption color
  37. A_TEXTCOLOR   equ 0x00FFFFFF ; Active text color
  38.  
  39. WIN_X         equ 265
  40. WIN_Y         equ 50;175
  41. WIN_W         equ 595
  42. WIN_H         equ 415 ;570
  43. WIN_COLOR     equ 0x040099BB;0x04EEEEEE
  44.  
  45. ITEM_BUTTON_W         equ 192;100
  46. ITEM_BUTTON_H         equ 23
  47. ITEM_BUTTON_SPACE     equ 0
  48. FIRST_ITEM_BUTTON_ID  equ 7
  49.  
  50. BUT_W         equ 80
  51. BUT_H         equ 20
  52.  
  53. MAX_HOTKEYS_NUM equ 15 ;  Bad bounding :/. Until we have normal listbox control.
  54. PATH_MAX_CHARS equ 255
  55.  
  56. @use_library
  57.  
  58. STARTAPP:
  59.         ; Initialize memory
  60.         mcall   68, 11
  61.         or      eax,eax
  62.         jz      close_app
  63.         ; Import libraries
  64.         sys_load_library  boxlib_name, sys_path, boxlib_name, system_dir0, err_message_found_lib, head_f_l, myimport,err_message_import, head_f_i
  65.         cmp     eax,-1
  66.         jz      close_app
  67.         stdcall dll.Load,importTable
  68.         test    eax, eax
  69.         jnz     close_app
  70.  
  71.         mcall   68, 12, MAX_HOTKEYS_NUM*PATH_MAX_CHARS   ; Get memory for editboxes text
  72.         mov     dword [buf_cmd_line], eax
  73.         mov     dword [edit1.text],   eax
  74.         mcall   68, 12, MAX_HOTKEYS_NUM*PATH_MAX_CHARS
  75.         mov     dword [buf_cmd_params], eax
  76.         mov     dword [edit2.text],     eax
  77.         mcall   68, 12, MAX_HOTKEYS_NUM*32
  78.         mov     dword [it_buf_cmd_line], eax
  79.         mov     dword [it_edit.text],    eax
  80.  
  81.         call    Load_HotkeyList
  82.  
  83.         mcall   66, 1, 1  ; Set keyboard mode to get scancodes.
  84.         mcall   26, 2, 1, ascii_keymap
  85.  
  86. get_mykey_window_slot_number:
  87.         call    draw_window
  88.         mcall   18, 7
  89.         mov     [mykey_window], eax
  90.  
  91. set_event_mask:
  92.         mcall    40, 39
  93.  
  94. red:
  95.       .test_slot:
  96.         mcall   18, 7
  97.         mov     ebx, [mykey_window]
  98.         cmp     eax, ebx
  99.         jne     @f
  100.  
  101.         mov     ecx, [it_window]
  102.         cmp     ebx, ecx
  103.         je      @f
  104.       .activate_it_window:
  105.         mov     al,  byte [it_alive]
  106.         test    al,  al
  107.         jz      @f
  108.         mov     byte [it_alive], 0
  109.  
  110.         mcall   18, 3                       ; Activate input thread window
  111.       @@:
  112.         call    draw_window
  113.  
  114. still:
  115.         call    reset_modifiers
  116.  
  117.         mcall   10               ; Wait for an event in the queue.
  118.  
  119.         cmp     al,1                  ; redraw request ?
  120.         jz      red
  121.         cmp     al,2                  ; key in buffer ?
  122.         jz      key
  123.         cmp     al,3                  ; button in buffer ?
  124.         jz      button
  125.         cmp     al,6
  126.         jz      mouse
  127.  
  128.         jmp     still
  129.  
  130. key:
  131.         mcall   2
  132.  
  133.         push    eax
  134.         mcall   66, 3
  135.         ;mov     edx, eax
  136.         ;and     edx, 0x00000FF;F
  137.         mov     dword [modifiers], eax;edx
  138.         pop     eax
  139.  
  140.         test    word [edit1.flags], 10b
  141.         jnz     .editbox_input
  142.         test    word [edit2.flags], 10b
  143.         jz      @f
  144.      .editbox_input:
  145.         cmp     ah, 0x80 ;if key up
  146.         ja      still
  147.         cmp     ah, 42 ;LShift
  148.         je      still
  149.         cmp     ah, 54 ;RShift
  150.         je      still
  151.         cmp     ah, 56 ;Alt
  152.         je      still
  153.         cmp     ah, 29 ;Ctrl
  154.         je      still
  155.         cmp     ah, 69 ;Pause/Break
  156.         je      still
  157.  
  158.        mov     esi, ascii_keymap
  159.        call    Scan2ASCII
  160.  
  161.        push dword edit1
  162.        call [edit_box_key]
  163.  
  164.        push dword edit2
  165.        call [edit_box_key]
  166.        jmp still
  167.      @@:
  168.  
  169.       ;------------------------
  170.         mov     cl, byte [hotkeys_num]
  171.      .test_next_hotkey:
  172.         dec     cl
  173.         mov     bl, cl
  174.         and     ebx, 0xFF
  175.         shl     ebx, 2;5
  176. ;        mov     esi, ebx
  177.         add     ebx, dword Hotkeys.codes
  178.  
  179.         mov     edx, dword [ebx]
  180.         cmp     ah, dl
  181.         jne     @f
  182.  
  183.         shr     edx, 8
  184.         cmp     edx, dword [modifiers]
  185.         jne     @f
  186.  
  187.         push    eax
  188.         mov     eax, PATH_MAX_CHARS
  189.         mul     cl
  190.         mov     edx, eax
  191.         add     edx, dword [buf_cmd_params]
  192.         add     eax, dword [buf_cmd_line]
  193.         mov     esi, eax
  194.         pop     eax
  195.         call    RunProgram
  196.         jmp     .end_test
  197.      @@:
  198.         or      cl, cl
  199.         jnz     .test_next_hotkey
  200.      .end_test:
  201.       ;------------------------
  202.  
  203.         jmp     still
  204.  
  205. button:
  206.         mcall   17             ; Get pressed button code
  207.         cmp     ah, 1               ; Test x button
  208.         je      close_app
  209.  
  210.         cmp     ah, 2
  211.         jne     @f
  212.         call    AddHotKey
  213.         jmp     red
  214.        @@:
  215.         cmp     ah, 5
  216.         jne     @f
  217.         call    Load_HotkeyList
  218.         jmp     red
  219.        @@:
  220.         cmp     ah, 6
  221.         jne     @f
  222.         call    WriteIni
  223.         xor     edx, edx
  224.         mov     esi, aRamSaver
  225.         call    RunProgram
  226.        @@:
  227.  
  228.         cmp     ah, FIRST_ITEM_BUTTON_ID     ; Test if pressed buttons
  229.         jb      still                        ; is a HotKey button...
  230.         mov     al, ah
  231.         sub     al, FIRST_ITEM_BUTTON_ID
  232.         cmp     al, byte [hotkeys_num]
  233.         jnb     still                        ; ...so, if not then still,
  234.  
  235.  
  236.         mov     byte [butt], ah           ; if yes then save pressed button ID
  237.         and     eax, 0xFF
  238.         mov     cl, byte PATH_MAX_CHARS
  239.         mul     cl
  240.         mov     ebx, eax
  241.         add     ebx, dword [buf_cmd_params]
  242.         add     eax, dword [buf_cmd_line]
  243.  
  244.         mov     dword [edit1.text], eax
  245.         mov     dword [edit2.text], ebx
  246.  
  247.         mov     esi, eax
  248.         call    strlen
  249.         mov     dword [edit1.size], ecx
  250.         mov     dword [edit1.pos], ecx
  251.  
  252.         mov     esi, ebx
  253.         call    strlen
  254.         mov     dword [edit2.size], ecx
  255.         mov     dword [edit2.pos], ecx
  256.  
  257.         jmp     red
  258.  
  259. mouse:
  260.         push    dword edit1
  261.         call    [edit_box_mouse]
  262.         push    dword edit2
  263.         call    [edit_box_mouse]
  264.  
  265.         jmp     still
  266.  
  267.  
  268. close_app:
  269.         mov     eax,-1                  ; close this program
  270.         int     0x40
  271.  
  272.  
  273. draw_window:
  274.         start_draw_window WIN_X,WIN_Y,WIN_W,WIN_H,WIN_COLOR,labelt, 11;labellen-labelt
  275.  
  276.         ;bar         5, 24, 585, 385, 0x800000 or 0x90D2
  277.         ;rectangle2  6, 25, 585, 385, 0xFFFFFF, 0
  278.  
  279.         ;bar         5, 24, BUT_W+4, 350, 0x008C00D2;0x800000 or A_KEYCOLOR
  280.         ;rectangle2  6, 25, BUT_W+4, 350, 0xFFFFFF, 0
  281.  
  282.  
  283.         push    dword edit1
  284.         call    [edit_box_draw]
  285.         push    dword edit2
  286.         call    [edit_box_draw]
  287.  
  288.         stdcall draw_button,   7,WIN_H-BUT_H-10,BUT_W,BUT_H,2,0x0050D250,AddKeyText,   0,C_TEXTCOLOR    ; Add Hotkey.
  289.     if 0
  290.         stdcall draw_button,  90,WIN_H-BUT_H-10,BUT_W,BUT_H,3,C_KEYCOLOR,DeleteKeyText,0,C_TEXTCOLOR    ; Delete Hotkey.
  291.         stdcall draw_button, 173,WIN_H-BUT_H-10,BUT_W,BUT_H,4,C_KEYCOLOR,ManageKeyText,0,C_TEXTCOLOR    ; Manage Hotkey.
  292.     end if
  293.         stdcall draw_button,   WIN_W-BUT_W*2-14,WIN_H-BUT_H-10,BUT_W,BUT_H,5,0x0050D250,ReloadKeyText,   0,C_TEXTCOLOR    ; Save Hotkeys list.
  294.         stdcall draw_button,   WIN_W-BUT_W-7,WIN_H-BUT_H-10,BUT_W,BUT_H,6,0x0050D250,SaveKeyText,   0,C_TEXTCOLOR    ; Save Hotkeys list.
  295.  
  296.         movzx   ecx, byte [hotkeys_num]
  297.         cmp     ecx, MAX_HOTKEYS_NUM
  298.         jng     @f
  299.         mov     ecx, MAX_HOTKEYS_NUM
  300.      @@:
  301.         mov     eax, 30
  302.         mov     ebx, FIRST_ITEM_BUTTON_ID
  303.      @@:
  304.         or      cl, cl
  305.         jz      @f
  306.  
  307.         mov     edx, ebx
  308.         sub     edx, FIRST_ITEM_BUTTON_ID
  309.         shl     edx, 5; edx=edx*32
  310.         add     edx, dword Hotkeys
  311.  
  312.         cmp     bl, byte [butt]
  313.         jne     .l1
  314.         stdcall draw_button, 7,eax,ITEM_BUTTON_W,ITEM_BUTTON_H,ebx,A_KEYCOLOR  ,edx,0,CA_TEXTCOLOR
  315.         bar         220, 70, 350, 30, 0x00C8E1F0 ;0x800000 or A_KEYCOLOR
  316.         rectangle2  221, 71, 350, 30, 0xFFFFFF, 0
  317.         mov     esi, Hotkeys.code_names
  318.         sub     edx, dword Hotkeys
  319.         shl     edx, 1
  320.         add     esi, edx
  321.         stdcall outtextxy, 225, 80, esi, 64, C_TEXTCOLOR
  322.         jmp     .l2
  323.      .l1:
  324.         stdcall draw_button, 7,eax,ITEM_BUTTON_W,ITEM_BUTTON_H,ebx,N_KEYCOLOR,edx,0,C_TEXTCOLOR
  325.      .l2:
  326.  
  327.         add     eax, ITEM_BUTTON_H+ITEM_BUTTON_SPACE
  328.         inc     ebx
  329.         dec     cl
  330.         jmp     @b
  331.       @@:
  332.         end_draw_window
  333. ret
  334.  
  335.  
  336. AddHotKey:
  337.         mov     al, byte [hotkeys_num]
  338.         cmp     al, MAX_HOTKEYS_NUM
  339.         jge     .end
  340.         inc     al
  341.         mov     byte [hotkeys_num], al
  342.  
  343.         mcall   51, 1, dword start_input_thread, dword input_thread_stack_top
  344.     .end:
  345. ret
  346.  
  347.  
  348. Load_HotkeyList:
  349.         call    ReadIni
  350.  
  351.         mov     al, byte [butt]
  352.         and     eax, 0xFF
  353.         sub     al, FIRST_ITEM_BUTTON_ID
  354.         mov     cl, byte PATH_MAX_CHARS
  355.         mul     cl
  356.         mov     ebx, eax
  357.         add     eax, dword [buf_cmd_line]
  358.         add     ebx, dword [buf_cmd_params]
  359.  
  360.  
  361.         ;mov  [butt], FIRST_ITEM_BUTTON_ID
  362.         mov     esi, eax
  363.         call    strlen
  364.         mov     dword [edit1.size], ecx
  365.         mov     dword [edit1.pos], ecx
  366.  
  367.         mov     esi, ebx
  368.         call    strlen
  369.         mov     dword [edit2.size], ecx
  370.         mov     dword [edit2.pos], ecx
  371. ret
  372.  
  373.  
  374. reset_modifiers:
  375.         pusha
  376.         mov     esi, dword [it_hotkey_addr]
  377.         test    esi, esi
  378.         jz      .end_set_mods
  379.  
  380.         lodsd
  381.  
  382.         ; Set new hotkey for the main thread
  383.         mov     cl, al
  384.         shr     eax, 8
  385.  
  386.         xor    edx, edx
  387.         push    cx
  388.         mov    cl, 3
  389.      .next_pair:
  390.         shl    edx, 4
  391.         mov    bl, al
  392.         and    bl, 3
  393.  
  394.         or     bl, bl
  395.         jz     .l1
  396.  
  397.         cmp    bl, 3 ; both?
  398.         jne    @f
  399.         or     dl, 2
  400.         jmp    .l1
  401.       @@:
  402.         add    bl, 2
  403.         or     dl, bl
  404.       .l1:
  405.         shr    eax, 2
  406.         dec    cl
  407.         test   cl, cl
  408.         jnz    .next_pair
  409.  
  410.         mov    bx, dx
  411.         and    bx, 0xF0F
  412.         xchg   bl, bh
  413.         and    dx, 0x0F0
  414.         or     dx, bx
  415.         pop    cx
  416.  
  417.         mcall   66, 4
  418.         mov     dword [it_hotkey_addr], 0
  419.      .end_set_mods:
  420.         popa
  421. ret
  422.  
  423.  
  424. ;######################## Input Thread code start  ##########################
  425.  
  426. start_input_thread:
  427.         mov     ecx, 1     ; to get scancodes.
  428.         mcall   26, 2, 1, it_ascii_keymap
  429.         mcall   66, 1      ; Set keyboard mode
  430.         mov     dword [it_hotkey_addr], 0
  431. it_set_editbox:
  432.         mov     al, byte [hotkeys_num]
  433.         sub     al, 1
  434.         and     eax, 0xFF
  435.         shl     eax, 5
  436.         add     eax, dword Hotkeys.names
  437.         mov     dword [it_edit.text], eax
  438.  
  439.         mov     esi, eax
  440.         call    strlen
  441.         mov     dword [it_edit.size], ecx
  442.         mov     dword [it_edit.pos], ecx
  443. get_it_window_slot_number:
  444.         call    it_draw_window
  445.         mcall   18, 7
  446.         mov     [it_window], eax
  447.  
  448. it_set_event_mask:
  449.         mcall   40, 39
  450. it_red:
  451.         call    it_draw_window
  452.  
  453. it_still:
  454.         mcall   10               ; Wait for an event in the queue.
  455.  
  456.         cmp     al,1                  ; redraw request ?
  457.         jz      it_red
  458.         cmp     al,2                  ; key in buffer ?
  459.         jz      it_key
  460.         cmp     al,3                  ; button in buffer ?
  461.         jz      it_button
  462.         cmp     al,6
  463.         jz      it_mouse
  464.  
  465.         jmp     it_still
  466.  
  467. it_key:
  468.         mcall   2
  469.  
  470.         mov     byte [it_keycode], 0
  471.         stdcall outtextxy, 10, 100, ctrl_key_names, 35, 0
  472.  
  473.         cmp     ah, 1 ;Esc
  474.         jne     @f
  475.         dec     byte [hotkeys_num]
  476.         jmp     close_app
  477.       @@:
  478.  
  479.         cmp     ah, 0x80 ;if key up
  480.         ja      .end
  481.         cmp     ah, 42 ;[Shift] (left)
  482.         je      .end
  483.         cmp     ah, 54 ;[Shift] (right)
  484.         je      .end
  485.         cmp     ah, 56 ;[Alt]
  486.         je      .end
  487.         cmp     ah, 29 ;[Ctrl]
  488.         je      .end
  489.         cmp     ah, 69 ;[Pause Break]
  490.         je      .end
  491.  
  492.         mov     byte [it_keycode], ah
  493.         mov     esi, it_ascii_keymap
  494.         call    Scan2ASCII
  495.  
  496.         test    word [it_edit.flags], 10b
  497.         jz      .end
  498.         push    dword it_edit
  499.         call    [edit_box_key]
  500.         jmp     it_still
  501.       .end:
  502.  
  503.         mcall   26, 2, 1, it_ascii_keymap
  504.         call    it_test_key_modifiers
  505.         test    dl, 3
  506.         jz      @f
  507.         push    edx
  508.         mcall   26, 2, 2, it_ascii_keymap
  509.         pop     edx
  510.       @@:
  511.  
  512.         mov     al, byte [it_keycode]
  513.         test    al, al
  514.         jz      @f
  515.         shl     edx, 8
  516.         mov     dl, al
  517.  
  518.         mov     eax, dword [it_hotkey_addr]
  519.         test    eax, eax
  520.         jnz     @f
  521.  
  522.         call    it_set_keycode_name
  523.  
  524.         mov     al, byte [hotkeys_num]
  525.         dec     al
  526.         and     eax, 0xFF
  527.         shl     eax, 2;5
  528.         add     eax, dword Hotkeys.codes
  529.         mov     dword [eax], edx
  530.         mov     dword [it_hotkey_addr], eax
  531.  
  532.         mov     cl, dl ; finally set hotkey
  533.         shr     edx, 8
  534.         mcall   66, 4
  535.       @@:
  536.  
  537.         jmp     it_still
  538.  
  539.  
  540. it_test_key_modifiers:
  541.         push    eax
  542.         mcall   66, 3 ;get control keys state
  543.         mov     edx,  eax
  544.         ;and     edx,  0x00000FFF
  545.       .lshift:
  546.         test    al, 1  ; LShift ?
  547.         jz      .rshift
  548.         stdcall outtextxy, 10, 100, ctrl_key_names, 6, A_TEXTCOLOR
  549.       .rshift:
  550.         test    al, 2  ; RShift ?
  551.         jz      .lctrl
  552.         stdcall outtextxy, 184, 100, ctrl_key_names+29, 6, A_TEXTCOLOR
  553.       .lctrl:
  554.         test    al, 4  ; LCtrl ?
  555.         jz      .rctrl
  556.         stdcall outtextxy, 52, 100, ctrl_key_names+7, 5, A_TEXTCOLOR
  557.       .rctrl:
  558.         test    al, 8  ; RCtrl ?
  559.         jz      .lalt
  560.         stdcall outtextxy, 148, 100, ctrl_key_names+23, 5, A_TEXTCOLOR
  561.       .lalt:
  562.         test    al, 0x10  ; LAlt ?
  563.         jz      .ralt
  564.         stdcall outtextxy, 88, 100, ctrl_key_names+13, 4, A_TEXTCOLOR
  565.       .ralt:
  566.         test    al, 0x20  ; RAlt ?
  567.         jz      @f
  568.         stdcall outtextxy, 118, 100, ctrl_key_names+18, 4, A_TEXTCOLOR
  569.       @@:
  570.         pop     eax
  571. ret
  572.  
  573.  
  574. it_set_keycode_name:
  575.         pusha
  576.         mov     al, byte [hotkeys_num]
  577.         dec     al
  578.         and     eax, 0xFF
  579.         shl     eax, 6
  580.         mov     edi, Hotkeys.code_names
  581.         add     edi, eax
  582.  
  583.         mov     ecx, 64
  584.         xor     ax, ax
  585.         call    strnset
  586.         mcall   66, 3 ;get control keys state
  587.       .lshift:
  588.         test    al, 1  ; LShift ?
  589.         jz      .rshift
  590.         mov     esi, ctrl_key_names
  591.         mov     ecx, 6
  592.         call    strncat
  593.  
  594.         mov     esi, aPlus
  595.         mov     ecx, 3
  596.         call    strncat
  597.         ;stdcall outtextxy, 10, 100, ctrl_key_names, 6, 0x00FF0000
  598.       .rshift:
  599.         test    al, 2  ; RShift ?
  600.         jz      .lctrl
  601.         mov     esi, ctrl_key_names+29
  602.         mov     ecx, 6
  603.         call    strncat
  604.  
  605.         mov     esi, aPlus
  606.         mov     ecx, 3
  607.         call    strncat
  608.         ;stdcall outtextxy, 184, 100, ctrl_key_names+29, 6, 0x00FF0000
  609.       .lctrl:
  610.         test    al, 4  ; LCtrl ?
  611.         jz      .rctrl
  612.         mov     esi, ctrl_key_names+7
  613.         mov     ecx, 5
  614.         call    strncat
  615.  
  616.         mov     esi, aPlus
  617.         mov     ecx, 3
  618.         call    strncat
  619.         ;stdcall outtextxy, 52, 100, ctrl_key_names+7, 5, 0x00FF0000
  620.       .rctrl:
  621.         test    al, 8  ; RCtrl ?
  622.         jz      .lalt
  623.         mov     esi, ctrl_key_names+23
  624.         mov     ecx, 5
  625.         call    strncat
  626.  
  627.         mov     esi, aPlus
  628.         mov     ecx, 3
  629.         call    strncat
  630.         ;stdcall outtextxy, 148, 100, ctrl_key_names+23, 5, 0x00FF0000
  631.       .lalt:
  632.         test    al, 0x10  ; LAlt ?
  633.         jz      .ralt
  634.         mov     esi, ctrl_key_names+13
  635.         mov     ecx, 4
  636.         call    strncat
  637.  
  638.         mov     esi, aPlus
  639.         mov     ecx, 3
  640.         call    strncat
  641.         ;stdcall outtextxy, 88, 100, ctrl_key_names+13, 4, 0x00FF0000
  642.       .ralt:
  643.         test    al, 0x20  ; RAlt ?
  644.         jz      @f
  645.         mov     esi, ctrl_key_names+18
  646.         mov     ecx, 4
  647.         call    strncat
  648.  
  649.         mov     esi, aPlus
  650.         mov     ecx, 3
  651.         call    strncat
  652.         ;stdcall outtextxy, 118, 100, ctrl_key_names+18, 4, 0x00FF0000
  653.       @@:
  654.         mov     esi, it_ascii_keymap
  655.         and     edx, 0xFF
  656.         add     esi, edx
  657.         mov     ecx, 1
  658.         call    strncat
  659.  
  660.         if 1;DEBUG
  661.           mov     esi, edi;Hotkeys.code_names
  662.           call    SysMsgBoardStr
  663.           newline
  664.         end if
  665.  
  666.         popa
  667. ret
  668.  
  669.  
  670. it_button:
  671.         mcall   17             ; Get pressed button code
  672.         cmp     ah, 1               ; Test x button
  673.         jne     @f
  674.         jmp     close_app
  675.       @@:
  676.         jmp     it_still
  677.  
  678. it_mouse:
  679.  
  680.         push    dword it_edit
  681.         call    [edit_box_mouse]
  682.  
  683.         jmp     it_still
  684.  
  685. it_draw_window:
  686.         start_draw_window 450,WIN_Y+250,225,70,WIN_COLOR,it_labelt, 26;labellen-labelt
  687.  
  688.         push    dword it_edit
  689.         call    [edit_box_draw]
  690.  
  691.         stdcall outtextxy, 43, 50, it_hint, 0, 0x323232
  692.         stdcall outtextxy, 10, 100, ctrl_key_names, 0, 0
  693.         ;stdcall draw_button,   7,WIN_H-30,80,20,2,C_KEYCOLOR,AddKeyText,   0,C_TEXTCOLOR    ; Add Hot key.
  694.         end_draw_window
  695.         mov     byte [it_alive], 1
  696. ret
  697.  
  698. ;######################## Input Thread code end ##########################
  699.  
  700.  
  701. ; Read configuration file
  702. ReadIni:
  703.         ; Get path
  704.         mov     edi, ini_path
  705.         mov     esi, app_path
  706.         call    strlen
  707.  
  708.       .get_path:
  709.         cmp     byte [app_path+ecx-1], '/'
  710.         je      @f
  711.         loop    .get_path
  712.       @@:
  713.         call    strncpy
  714.         mov     byte [ini_path+ecx], 0
  715.         mov     esi, aIni
  716.         call    strlen
  717.         call    strncat
  718.  
  719.         ; Get hotkey number
  720.         invoke  ini_get_int, ini_path, aMain, aKeynum, 0
  721.  
  722.         and     eax, 0xFF
  723.         test    al, al
  724.         jz      .end
  725.         cmp     al, MAX_HOTKEYS_NUM
  726.         jle     @f
  727.         mov     al, MAX_HOTKEYS_NUM
  728.       @@:
  729.         mov     byte [hotkeys_num], al
  730.  
  731.         mov     ecx, eax
  732.         xor     eax, eax
  733.       .get_next_hotkey_values:
  734.         call    set_next_hotkey_section_name
  735.         ; Get hotkey name
  736.         mov     edi, eax
  737.         shl     edi, 5 ; edi=eax*32
  738.         add     edi, dword Hotkeys
  739.         push    eax ecx
  740.         invoke  ini_get_str, ini_path, aHotkey, aName, edi, 32, 0
  741.         pop     ecx eax
  742.         ; Get hotkey code
  743.         mov     edi, eax
  744.         shl     edi, 2 ; edi=eax*4
  745.         add     edi, dword Hotkeys.codes
  746.         push    eax ecx edx
  747.         invoke  ini_get_int, ini_path, aHotkey, aKeycode, 0
  748.         mov     dword [it_hotkey_addr], edi
  749.         stosd
  750.         ; set hotkey
  751.         call    reset_modifiers
  752.         pop     edx ecx eax
  753.         ; Get hotkey code_name
  754.         mov     edi, eax
  755.         shl     edi, 6 ; edi=eax*64
  756.         add     edi, dword Hotkeys.code_names
  757.         push    eax ecx
  758.         invoke  ini_get_str, ini_path, aHotkey, aKeycodeName, edi, 64, 0
  759.         pop     ecx eax
  760.         ; Get hotkey path and param
  761.         push    eax ecx
  762.         mov     cl, byte PATH_MAX_CHARS
  763.         mul     cl
  764.         mov     edi, eax
  765.         push    edi
  766.         add     edi, dword [buf_cmd_line]
  767.         invoke  ini_get_str, ini_path, aHotkey, aPath, edi, 32, 0
  768.         pop     edi
  769.         add     edi, dword [buf_cmd_params]
  770.         invoke  ini_get_str, ini_path, aHotkey, aParam, edi, 32, 0
  771.         pop     ecx eax
  772.  
  773.         inc     al
  774.         dec     ecx
  775.         test    ecx, ecx
  776.         jnz    .get_next_hotkey_values
  777.     .end:
  778. ret
  779.  
  780.  
  781. ; Write configuration file
  782. WriteIni:
  783.         mov     edi, ini_path
  784.         ; Set hotkey number
  785.         movzx   ecx, byte [hotkeys_num]
  786.         invoke  ini_set_int, ini_path, aMain, aKeynum, ecx
  787.  
  788.         xor     eax, eax
  789.       .get_next_hotkey_values:
  790.         call    set_next_hotkey_section_name
  791.         ; Set hotkey name
  792.         push    eax ecx
  793.         mov     esi, eax
  794.         shl     esi, 5 ; edi=eax*32
  795.         add     esi, dword Hotkeys
  796.         call    strlen
  797.         invoke  ini_set_str, ini_path, aHotkey, aName, esi, ecx
  798.         pop     ecx eax
  799.         ; Set hotkey code
  800.         mov     esi, eax
  801.         shl     esi, 2 ; edi=eax*4
  802.         add     esi, dword Hotkeys.codes
  803.         push    eax ecx edx
  804.         invoke  ini_set_int, ini_path, aHotkey, aKeycode, dword [esi]
  805.         pop     edx ecx eax
  806.         ; Set hotkey code_name
  807.         mov     esi, eax
  808.         shl     esi, 6 ; edi=eax*64
  809.         add     esi, dword Hotkeys.code_names
  810.         push    eax ecx
  811.         call    strlen
  812.         invoke  ini_set_str, ini_path, aHotkey, aKeycodeName, esi, ecx
  813.         pop     ecx eax
  814.         ; Set hotkey path and param
  815.         push    eax ecx
  816.         ;inc     al
  817.         mov     cl, byte PATH_MAX_CHARS
  818.         mul     cl
  819.         mov     esi, eax
  820.         push    esi
  821.         add     esi, dword [buf_cmd_line]
  822.         call    strlen
  823.         invoke  ini_set_str, ini_path, aHotkey, aPath, esi, ecx
  824.         pop     esi
  825.         add     esi, dword [buf_cmd_params]
  826.         call    strlen
  827.         invoke  ini_set_str, ini_path, aHotkey, aParam, esi, ecx
  828.         pop     ecx eax
  829.  
  830.         inc     al
  831.         dec     ecx
  832.         test    ecx, ecx
  833.         jnz    .get_next_hotkey_values
  834.     .end:
  835. ret
  836.  
  837.  
  838. set_next_hotkey_section_name:           ;(eax - num)
  839. ; this code mainly from debug.inc
  840.         push    eax ecx edi
  841.         mov     edi, aHotkey
  842.         add     edi, 6 ; + strlen("hotkey")
  843.         mov     ecx, 10
  844.         push    -'0'
  845.     .l0:
  846.         xor     edx, edx
  847.         div     ecx
  848.         push    edx
  849.         test    eax, eax
  850.         jnz     .l0
  851.     .l1:
  852.         pop     eax
  853.         add     al, '0'
  854.         ;call   debug_outchar
  855.         stosb
  856.         jnz     .l1
  857.         pop     edi ecx eax
  858. ret
  859.  
  860.  
  861. ;****************************************
  862. ;*  input:  esi = pointer to keymap     *
  863. ;*           ah  = scan code            *
  864. ;*  output:  ah  = ascii code           *
  865. ;****************************************
  866. Scan2ASCII:
  867.         push    esi
  868.         shr     eax, 8
  869.         add     esi, eax
  870.         lodsb
  871.         shl     eax, 8
  872.         pop     esi
  873. ret
  874.  
  875.  
  876.  
  877. ;********************************************
  878. ;*  input:  esi = pointer to the file name  *
  879. ;*          edx = pointer to the parametrs  *
  880. ;********************************************
  881.  
  882. RunProgram:
  883.     pusha
  884.     mov      dword [InfoStructure],    7   ; run program
  885.     mov      dword [InfoStructure+4],  0   ; flags
  886.     mov      dword [InfoStructure+8],  edx ; pointer to the parametrs
  887.     mov      dword [InfoStructure+12], 0   ; reserved
  888.     mov      dword [InfoStructure+16], 0   ; reserved
  889.     mov      dword [InfoStructure+20], 0   ; reserved
  890.     mov      dword [InfoStructure+21], esi ; pointer to the file name
  891.     mcall    70, InfoStructure
  892.     cmp      eax, 0
  893.     jl       .err_out
  894.   .out:
  895.     popa
  896.     clc
  897.     ret
  898.   .err_out:
  899.     print    "Can't load program"
  900.     popa
  901.     stc
  902.     ret
  903.  
  904.  
  905. ; DATA AREA
  906.  
  907. ; Application Title
  908. labelt          db      'MyKey v.0.2'
  909. mykey_window    dd      0          ; Slot number of MyKey
  910.  
  911.  
  912. ;########### Input Thread data start ############
  913.  
  914. ; Input Thread Title
  915. it_labelt       db      "Input hotkey and it's name"
  916. ;labellen:
  917. it_edit edit_box 180, 20, 30, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, 31, it_buf_cmd_line, 0, 0
  918. it_buf_cmd_line   dd      0 ;db MAX_HOTKEYS_NUM*32 dup(0)  ; !Make it dynamic!!!
  919. it_window         dd      0          ; Slot number of the input thread
  920. it_alive          db      0          ; Flag of the input thread existance
  921. it_keycode        db      0
  922. it_hotkey_addr    dd      0
  923. it_hint           db      'or press Esc to cancel',0
  924. ;########### Input Thread data end   ############
  925.  
  926. ;Button names
  927. AddKeyText      db 'Add',0
  928. ReloadKeyText   db 'Reload',0
  929. SaveKeyText     db 'Save',0
  930. ;DeleteKeyText   db 'Delete',0
  931. ;ManageKeyText   db 'Manage',0
  932.  
  933.  
  934. hotkeys_num   db 0;15
  935. ;keyboard_mode db 0       ; Scan or ASCII keys to send ?  0 - ASCII , 1 - Scan
  936. butt          db FIRST_ITEM_BUTTON_ID       ; Pressed button ID
  937. modifiers     dd 0
  938.  
  939. ;Data structures for loadlib.mac and editbox_ex.mac [
  940. edit1 edit_box 350, 220, 30, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, PATH_MAX_CHARS+1, buf_cmd_line, 0, 0
  941. edit2 edit_box 350, 220, 50, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, PATH_MAX_CHARS+1, buf_cmd_params, 0, 0
  942.  
  943. buf_cmd_line   dd 0 ;db MAX_HOTKEYS_NUM*PATH_MAX_CHARS dup(0)  ; !Make it dynamic!!!
  944. buf_cmd_params dd 0 ;db MAX_HOTKEYS_NUM*PATH_MAX_CHARS dup(0)  ; !Make it dynamic!!!
  945.  
  946. sys_path:
  947. system_dir0 db '/sys/lib/'
  948. boxlib_name db 'box_lib.obj',0
  949.  
  950. err_message_found_lib   db "Can't find box_lib.obj",0
  951. head_f_i:
  952. head_f_l                db 'System error',0
  953. err_message_import      db 'Error on import box_lib.obj',0
  954.  
  955. align 4
  956. myimport:
  957. edit_box_draw   dd  aEdit_box_draw
  958. edit_box_key    dd  aEdit_box_key
  959. edit_box_mouse  dd  aEdit_box_mouse
  960. version_ed      dd  aVersion_ed
  961.                 dd  0,0
  962.  
  963. aEdit_box_draw  db 'edit_box',0
  964. aEdit_box_key   db 'edit_box_key',0
  965. aEdit_box_mouse db 'edit_box_mouse',0
  966. aVersion_ed     db 'version_ed',0
  967.  
  968. align 16
  969. importTable:
  970. library                                                 \
  971.         libini, 'libini.obj';,                           \
  972. ;        boxlib, 'boxlib.obj',                           \
  973. ;        libio, 'libio.obj',                            \
  974.  
  975. ;import  boxlib, \
  976. ;edit_box_draw  , 'edit_box', \
  977. ;edit_box_key   , 'edit_box_key', \
  978. ;edit_box_mouse , 'edit_box_mouse', \
  979. ;version_ed     , 'version_ed'
  980.  
  981.  
  982. import  libini, \
  983.         ini_get_str  ,'ini_get_str', \
  984.         ini_set_str  ,'ini_set_str', \
  985.         ini_get_int  ,'ini_get_int', \
  986.         ini_set_int  ,'ini_set_int';, \
  987. ;        ini_get_color,'ini_get_color', \
  988. ;        ini_set_color,'ini_set_color'
  989.  
  990.  
  991. ;] Data structures for loadlib.mac and editbox_ex.mac
  992.  
  993. InfoStructure:
  994.                      dd      0x0     ; subfunction number
  995.                      dd      0x0     ; position in the file in bytes
  996.                      dd      0x0     ; upper part of the position address
  997.                      dd      0x0     ; number of     bytes to read
  998.                      dd      0x0     ; pointer to the buffer to write data
  999.                      db      0
  1000.                      dd      0       ; pointer to the filename
  1001.  
  1002.  
  1003. I_END:                    ; End of application code and data marker
  1004.  
  1005.    rb 300 ;input thread stack size
  1006. input_thread_stack_top:
  1007.  
  1008. ascii_keymap:
  1009.              db 128 dup(?)
  1010. ctrl_key_names db  'LShift LCtrl LAlt RAlt RCtrl RShift',0
  1011. aPlus          db  ' + ',0
  1012. aIni           db  'mykey.ini',0
  1013. aMain          db  'main',0
  1014. aKeynum        db  'keynum',0
  1015. aHotkey        db  'hotkey',0,0,0
  1016. aName          db  'name',0
  1017. aKeycode       db  'keycode',0
  1018. aKeycodeName   db  'keycode_name',0
  1019. aPath          db  'path',0
  1020. aParam         db  'param',0
  1021. aRamSaver      db  '/sys/rdsave',0
  1022.  
  1023. app_path       rb  255
  1024. ini_path       rb  255
  1025.  
  1026. Hotkeys:  ;(name = 32 b) + (modifiers = 3 b) + (keycode = 1 b) = 36 byte for 1 hotkey
  1027.     .names:
  1028.              db 'My1',0
  1029.              rb 28
  1030.              db 'My2',0
  1031.              rb 28
  1032.              db 'My3',0
  1033.              rb 28
  1034.              rb MAX_HOTKEYS_NUM*32-3
  1035.     .codes:
  1036.              dd MAX_HOTKEYS_NUM dup (0)
  1037.     .code_names:
  1038.              rb MAX_HOTKEYS_NUM*64
  1039.  
  1040. it_ascii_keymap:
  1041.