Subversion Repositories Kolibri OS

Rev

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