Subversion Repositories Kolibri OS

Rev

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