News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Combo Hotkeys

Started by Crashish, July 07, 2007, 08:16:12 PM

Previous topic - Next topic

Crashish

How do you use combo hotkeys with GetAsyncKeyState?

Instead of doing...
invoke GetAsyncKeyState, VK_W

I want to use...
invoke GetAsyncKeyState, VK_SHIFT+VK_W

I've searched the forum but didn't seen anything specifically on this subject or I didn't know what
exactly to search for.


Example:

.data
bHidden db 0

.code

invoke GetAsyncKeyState,VK_W          ;// VK_SHIFT and VK_W    is what I'd like to use for instance
.IF eax!=0
.if bHidden == 0
invoke ShowWindow, hWin, SW_HIDE
inc bHidden

.elseif bHidden == 1
invoke ShowWindow, hWin, SW_SHOW
dec bHidden
.endif
        .ENDIF


I'm just wanting to use multiple hotkeys in combination with one another, just like when you bring up
task manager in xp by pressing Control+Alt+Delete.

Thanks for your help guys

ramguru

I'm using GetKeyState for such combos:


...
.elseif uMsg == WM_KEYDOWN
invoke GetKeyState, VK_SHIFT
mov    esi, eax
shr    esi, 15
invoke GetKeyState, VK_CONTROL
mov    edi, eax
shr    edi, 15
.if esi && wParam == VK_A
; shift+A
.elseif esi && edi && wParam == VK_B
; shift+ctrl+B
.endif
...

zooba

The best (not necessarily simplest, but it's pretty good) way of doing this is to use accelerators. Have a look at the CreateAcceleratorTable and TranslateAccelerator functions.

Cheers,

Zooba :U

Crashish

Thanks for your help guys and for your example ramguru.


Jackal

I did it by using the RegisterHotKey api..


  invoke RegisterHotKey,hWnd,065h,MOD_CONTROL, 041h ; CTRL + A (041h is 65 - 065h is 101)


when the hot keys are triggered your window will recieve a message..


    cmp uMsg, WM_HOTKEY
    jne @F
      Invoke DialogBoxParam, hInstance, addr sAllDiagName, hWnd, OFFSET SelectAllProcDiag, 0
     jmp Return
    @@:

zooba

That's fine, but just remember that hotkeys are global and can be used even when your application is not active. Also keep in mind that the RegisterHotKey call will fail if another application has already registered that hotkey. It may also cause other programs to not recognise the key combination, though I haven't tested this.

If these are issues, I strongly recommend you look into accelerator keys. There's a few lines required to set one up, but then they are passed as WM_COMMAND messages with a unique (if desired) id.

Cheers,

Zooba :U