News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Detect NumPad

Started by jj2007, May 09, 2015, 05:21:47 AM

Previous topic - Next topic

jj2007

My idea was to test if the notebook has, hardware-wise, a NumPad or not:

CheckKeyboard proc
LOCAL bytes, rid:RID_DEVICE_INFO, devs[100]:RAWINPUTDEVICELIST
  m2m rid.cbSize, RID_DEVICE_INFO
  push 127
  mov eax, esp
  invoke GetRawInputDeviceList, addr devs, eax, RAWINPUTDEVICELIST
  pop ecx
  For_ ebx=0 To eax-1
imul ecx, ebx, RAWINPUTDEVICELIST
.if devs.dwType[ecx]==RIM_TYPEKEYBOARD
m2m bytes, RID_DEVICE_INFO
push ecx
invoke GetRawInputDeviceInfo, devs.hDevice[ecx], RIDI_DEVICEINFO, addr rid, addr bytes
pop ecx
Print Str$("\n## %i keys", rid.keyboard.dwNumberOfKeysTotal)
Print Str$("\ndwType      \t%i", rid.keyboard.dwType)
Print Str$("\ndwSubType\t%i", rid.keyboard.dwSubType)
Print Str$("\ndwNumberOfFunctionKeys\t%i", rid.keyboard.dwNumberOfFunctionKeys)
Print Str$("\ndwNumberOfIndicators\t%i", rid.keyboard.dwNumberOfIndicators)
Print Str$("\ndwKeyboardMode\t%i\n", rid.keyboard.dwKeyboardMode)
.endif
  Next
  ret
CheckKeyboard endp


Full source & exe attached. The problem: My two notebooks report 101 keys, and all the rest is also identical:
## 101 keys
dwType          81
dwSubType       0
dwNumberOfFunctionKeys  12
dwNumberOfIndicators    3
dwKeyboardMode  1

## 101 keys
dwType          4
dwSubType       0
dwNumberOfFunctionKeys  12
dwNumberOfIndicators    3
dwKeyboardMode  1


But only one does have a real, physical NumPad, the other one has only a NumLock key that makes u i o behave like 4 5 6 etc.

Any ideas?

MichaelW

My notebook does have a number pad, are these the results you expect?:

## 101 keys
dwType          7
dwSubType       0
dwNumberOfFunctionKeys  12
dwNumberOfIndicators    3
dwKeyboardMode  1

Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Thanks, Michael.

Yes, looks very similar to mine (I wonder why I got two of them, for both notebooks ::))

I had hoped to see a difference in the total number of keys, but apparently the virtual "Fn" keys are added to the physical key count, so numpad or not, you get the same results. It's opaque to the programmer :(

sinsi

    mov answer, input("Does your laptop have a separate NumPad?")
:biggrin:
🍺🍺🍺

jj2007

That is indeed the only solution, it seems. Incredible that there is no numpad detector among the many thousand Windows API functions :(