Subversion Repositories Kolibri OS

Rev

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