BBjKeypressEvent::getKeyLocation

Description

In BBj 19.10 and higher, this method returns a flag that indicates the location of the key on the keyboard.

Syntax

Return Value Method
int getKeyLocation()

Parameters

None.

Return Value

Returns one of the following values indicating key location on the keyboard:

BBjKeypressEvent Constant Value Comments
KEY_LOCATION_UNKNOWN 0 The key location could not be determined.
KEY_LOCATION_STANDARD 1 There is only one version of this key, and this wasn't on the numeric keypad.
KEY_LOCATION_LEFT 2 There are two versions of this key, on the left and right sides of the keyboard, and the left-hand version was pressed.
KEY_LOCATION_RIGHT 3 There are two versions of this key, on the left and right sides of the keyboard, and the right-hand version was pressed.
KEY_LOCATION_NUMPAD 4 This key is on the numeric keypad.

Remarks

None.

Example

rem ' keypress
begin
sysgui=unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
x = 25
y = 25
w = 800
h = 500
window! = sysgui!.addWindow(x,y,w,h,"keypress",$20090083$,$00400400$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.setCallback(window!.ON_RESIZE,"resize")
window!.setCallback(window!.ON_KEYPRESS,"keypress")
cedit! = window!.addCEdit(101,0,0,w,h,"",$83a2$)
cedit!.setWrapStyleWord(0)
dim event$:tmpl(sysgui)
process_events
eoj:
   release
resize:
   event! = sysgui!.getLastEvent()
   cedit!.setSize(event!.getWidth(),event!.getHeight())
return
keypress:
   event! = sysgui!.getLastEvent()
   event$ = sysgui!.getLastEventString()
   print fill(72,"=")
   key=event.id,flags$=event.flags$
   print "Window Keypress: ",hta(event.id$)," Flags: ",hta(event.flags$),": """,cvs(event.id$,16),""" = ",
   keycode=event.id; gosub keycode
   if key<=255 then gosub key
   print "getKeyChar():",num(event!.getKeyChar())
   print "getKeyCode():",num(event!.getKeyCode()),": ",
   keycode=event!.getKeyCode(); if keycode=0 then keycode=event!.getKeyChar()
   gosub keycode; print ""
   print "getKeyLocation(): ",fnLocation$(event!.getKeyLocation(err=*next)),event!.getKeyLocation(err=*next)
   print "getCapsLock(): ",event!.getCapsLock(err=*next)
   print "getNumLock(): ",event!.getNumLock(err=*next)
   print "isShiftDown(): ",event!.isShiftDown()
   print "isControlDown(): ",event!.isControlDown()
   print "isAltDown(): ",event!.isAltDown()
   print "isCmdDown(): ",event!.isCmdDown()
   print fill(72,"=")
   events = events + 1
   info$ = str(events)+" "+event!.getEventName()+" "
   if asc(and(flags$,$01$)) and key<>asc($10$) then info$ = info$ + "SHIFT+"
   if asc(and(flags$,$02$)) and key<>asc($11$) then info$ = info$ + "CTRL+"
   if asc(and(flags$,$04$)) and key<>asc($12$) then info$ = info$ + "ALT+"
   if asc(and(flags$,$08$)) and key<>asc($9d$) then info$ = info$ + "CMD+"
   info$ = info$ + key$
   keyChar = event!.getKeyChar()
   info$ = info$ + " (" + str(keyChar) + ")"
   if keyChar and keyChar<256 then info$ = info$ + " ["+chr(keyChar)+"]"
   info$ = info$ + " " +fnLocation$(event!.getKeyLocation())
   if event!.getCapsLock() then info$ = info$ + " (CAPSLOCK)"
   if event!.getNumLock() then info$ = info$ + " (NUMLOCK)"
   info$ = info$ + " event.id=$" + hta(bin(event.id)) + "$,event.flags=$"+hta(bin(event.flags))+"$,event.x=$"+hta(bin(event.x))+"$"
   cedit!.addParagraph(-1,info$)
   cedit!.highlight(-1,0,-1,0)
return
key:
   print ": ",
   if asc(and(flags$,$01$)) then print "SHIFT+",; if key=asc($10$) then print ""; return
   if asc(and(flags$,$02$)) then print "CTRL+",; if key=asc($11$) then print ""; return else key=key+64
   if asc(and(flags$,$04$)) then print "ALT+",; if key=asc($12$) then print ""; return
   if asc(and(flags$,$08$)) then print "CMD+",; if key=asc($9d$) then print ""; return
rem if asc(and(flags$,$0f$)) then print "+",
   if key<256 then print chr(key)
return
def fnLocation$(location)
   switch location
      case BBjKeypressEvent.KEY_LOCATION_UNKNOWN; return "KEY_LOCATION_UNKNOWN"; rem 0
      case BBjKeypressEvent.KEY_LOCATION_STANDARD; return "KEY_LOCATION_STANDARD"; rem 1
      case BBjKeypressEvent.KEY_LOCATION_LEFT; return "KEY_LOCATION_LEFT"; rem 2
      case BBjKeypressEvent.KEY_LOCATION_RIGHT; return "KEY_LOCATION_RIGHT"; rem 3
      case BBjKeypressEvent.KEY_LOCATION_NUMPAD; return "KEY_LOCATION_NUMPAD"; rem 4
      case default; return "KEY_LOCATION_UNKNOWN "+str(location)
   swend
fnend
keycode:
   keycode$=bin(keycode,2)
   if asc(and(keycode$,$1000$)) then print "SHIFT+",
   if asc(and(keycode$,$2000$)) then print "CTRL+",
   if asc(and(keycode$,$4000$)) then print "ALT+",
   if asc(and(keycode$,$8000$)) then print "CMD+",
  switch dec(and(keycode$,$0fff$))
   case dec($0008$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Backspace"; break
   case dec($0009$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Tab"; break
   case dec($000C$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Clear"; break
   case dec($0010$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Shift"; break
   case dec($0011$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Control"; break
   case dec($0012$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Alt"; break
   case dec($0013$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Pause"; break
   case dec($0014$); if asc(and(keycode$,$2000$)) then gosub keycode_default; break else key$ = "Caps Lock"; break
   case dec($001b$); key$ = "Escape"; break
   case dec($007f$); key$ = "Delete"; break
   case dec($0090$); key$ = "Num Lock"; break
   case dec($0091$); key$ = "Scroll Lock"; break
   case dec($009a$); key$ = "Print Screen"; break
   case dec($009d$); key$ = "Command"; break
   case dec($012d$); key$ = "Up arrow"; break
   case dec($012e$); key$ = "Down arrow"; break
   case dec($012f$); key$ = "Right arrow"; break
   case dec($0130$); key$ = "Left arrow"; break
   case dec($0131$); key$ = "Page up"; break
   case dec($0132$); key$ = "Page down"; break
   case dec($0133$); key$ = "Home"; break
   case dec($0134$); key$ = "End"; break
   case dec($0135$); key$ = "Ctrl-Home"; break
   case dec($0136$); key$ = "Ctrl-End"; break
   case dec($0138$); key$ = "Insert"; break
   case dec($0139$); key$ = "Ctrl-Right arrow"; break
   case dec($013a$); key$ = "Ctrl-Left arrow"; break
   case dec($013b$); key$ = "Backtab"; break
   case dec($013e$); key$ = "Keypad 0"; break
   case dec($013f$); key$ = "Keypad 1"; break
   case dec($0140$); key$ = "Keypad 2"; break
   case dec($0141$); key$ = "Keypad 3"; break
   case dec($0142$); key$ = "Keypad 4"; break
   case dec($0143$); key$ = "Keypad 5"; break
   case dec($0144$); key$ = "Keypad 6"; break
   case dec($0145$); key$ = "Keypad 7"; break
   case dec($0146$); key$ = "Keypad 8"; break
   case dec($0147$); key$ = "Keypad 9"; break
   case dec($014b$); key$ = "F1"; break
   case dec($014c$); key$ = "F2"; break
   case dec($014d$); key$ = "F3"; break
   case dec($014e$); key$ = "F4"; break
   case dec($014f$); key$ = "F5"; break
   case dec($0150$); key$ = "F6"; break
   case dec($0151$); key$ = "F7"; break
   case dec($0152$); key$ = "F8"; break
   case dec($0153$); key$ = "F9"; break
   case dec($0154$); key$ = "F10"; break
   case dec($0155$); key$ = "F11"; break
   case dec($0156$); key$ = "F12"; break
   case dec($0157$); key$ = "F13"; break
   case dec($0158$); key$ = "F14"; break
   case dec($0159$); key$ = "F15"; break
   case dec($015a$); key$ = "F16"; break
   case dec($015b$); key$ = "F17"; break
   case dec($015c$); key$ = "F18"; break
   case dec($015d$); key$ = "F19"; break
   case dec($015e$); key$ = "F20"; break
   case dec($015f$); key$ = "F21"; break
   case dec($0160$); key$ = "F22"; break
   case dec($0161$); key$ = "F23"; break
   case dec($0162$); key$ = "F24"; break
   case dec($0174$); key$ = "Keypad *"; break
   case dec($0175$); key$ = "Keypad -"; break
   case dec($0176$); key$ = "Keypad +"; break
   case dec($0177$); key$ = "Keypad /"; break
   case dec($020c$); key$ = "Windows"; break
   case dec($020d$); key$ = "Context Menu"; break
   case default
      gosub keycode_default
      break
  swend
return
keycode_default:
  if asc(and(keycode$,$1000$)) and dec(and(keycode$,$0fff$))=asc($10$) then
     key$ = "Shift "+str(keycode); return
  endif
  if asc(and(keycode$,$2000$)) and dec(and(keycode$,$0fff$))=asc($11$) then
     key$ = "Ctrl "+str(keycode); return
  endif
  if asc(and(keycode$,$4000$)) and dec(and(keycode$,$0fff$))=asc($12$) then
     key$ = "Alt "+str(keycode); return
  endif
  if asc(and(keycode$,$2000$)) and dec(and(keycode$,$0fff$))<=26 then
     keycode$=ior(keycode$,$0040$)
  endif
  key$ = chr(dec(and(keycode$,$00ff$)))
  if cvs(key$,16)=key$ then key$ = """"+key$+"""" else key$ = "$"+hta(key$)+"$"
  key$ = key$ + " ("+str(keycode)+")"
return

See Also

BBjKeypressEvent

BBjAPI

BBj Object Syntax

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.