The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Mark Jones on July 20, 2005, 02:08:21 PM

Title: Converting hotkey values (dec) to string
Post by: Mark Jones on July 20, 2005, 02:08:21 PM
Hotkeys are fun. :)

Here's a way I managed to manually convert a returned VKey into ASCII characters so it can be displayed or stored in an .ini file or whatever. Here the hotkey was F3 (VKEY=72h) A normal hex-to-string conversion will not work because the 72h represents a DECIMAL 72d, but in hex notation. Confusing!


        invoke SendDlgItemMessage,hWnd,IDC_HOT1,HKM_GETHOTKEY,0,0   ; result in eax
        mov ecx,offset szBuffer             ; dest buffer pointer as ecx
        shl eax,24                          ; strip off all but al (72h)
        shr eax,24                          ; move lone value back to al
        shl eax,4                           ; put each nibble in own byte (07h,20h)
        shr al,4                            ; correct al (07h,02h)
        add ax,3030h                        ; add 30h to each to make ASCII
        mov dh,al                           ; swap bytes
        mov dl,ah                           ; (32h,37h)
        mov word ptr [ecx], dx              ; output two bytes (in logical order)
Title: Re: Converting hotkey values (dec) to string
Post by: pro3carp3 on July 20, 2005, 05:44:43 PM
I'm not very familer with the SendDlgItemMessage function, but does the following do the same thing?


invoke SendDlgItemMessage,hWnd,IDC_HOT1,HKM_GETHOTKEY,0,0   ; result in eax
        mov ecx,offset szBuffer             ;??????????????????????
        mov ah, al
        shr al, 4
        and F0Fh
        add ax, 3030h
        mov word ptr [ecx], ax

Title: Re: Converting hotkey values (dec) to string
Post by: Jeff on July 20, 2005, 07:54:37 PM
i think you mean and ax,0F0Fh  ;)
Title: Re: Converting hotkey values (dec) to string
Post by: pro3carp3 on July 20, 2005, 08:45:22 PM
Quote
i think you mean and ax,0F0Fh  ;)

Oops...

I was in a hurry to go to lunch.  Thanks.
Title: Re: Converting hotkey values (dec) to string
Post by: comrade on July 21, 2005, 02:51:55 PM
can't u use BCD instructions for that... if 72h represents 72d then thats a bcd