title: Get keyboard type macOS and detect built-in, onscreen or USB
body: <p>I am developing an application to detect keyboard type for macOS. 
  I have seen several functions which reading the documentation are supposed to return keyboard id. </p>
  
  <p>However when I test those on my laptop it always print 59.</p>
  
  <p>Can someone tell me where does this 59 value come from and its meaning ??</p>
  
  <p>So far I have tried with oncreen keyboard and built-in keyboard. I have also tried with different layouts but I keep getting that 59</p>
  
  <p>This is my code:</p>
  
  <pre><code>- (CGEventRef)processEvent:(CGEventRef)cgEvent
  {
     uint32_t kbdType = LMGetKbdType();
     NSLog(@"Testing LMGetKbdType  ----------&gt; %d", kbdType);
     NSEvent* event = [NSEvent eventWithCGEvent:cgEvent];
  
     NSEventType type = [event type];
     if(type==NSKeyDown || type==NSKeyUp) {
        int64_t val = CGEventGetIntegerValueField(cgEvent, kCGKeyboardEventKeyboardType);
        NSLog(@"CGEventGetIntegerValueField: %lld",val);
        EventRef ce = (EventRef)[event eventRef];
  
        if(ce) {
           unsigned kbt;
           GetEventParameter(
                          ce,
                          kEventParamKeyboardType,
                          typeUInt32, NULL,
                          sizeof kbt, NULL,
                          &amp; kbt
                          );
  
           NSLog(@"CARBON Keyboard type: %d",kbt);
        }
  
        CGEventSourceRef evSrc = CGEventCreateSourceFromEvent( cgEvent );
  
        if(evSrc) {
           unsigned kbt = (NSUInteger) CGEventSourceGetKeyboardType( evSrc );
           CFRelease(evSrc);
           NSLog(@"COCOA: %d",kbt);
        }
     }
  }
  </code></pre>