Subversion Repositories Kolibri OS

Rev

Rev 1816 | Rev 1900 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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