Esempio n. 1
0
 def eng_turn(self, activity):
     #log('turn') # xxx
     #
     b_keep_running = self.api.process_windows_events()
     if not b_keep_running:
         activity.mark(l=self, s='received quit event')
         #
         zero_h = self.spin_h
         self.call_windows_event_quit(zero_h=zero_h)
     #
     b_another = True
     while b_another:
         self.api.get_next_event(self.ptr_event)
         (b0, b1, b2, b3, b4, b5, b6,
          b7) = struct.unpack('bbbbbbbb', self.event)
         if b0 == 0:
             # Setting b0 to 0 is the API's way of communicating to
             # us that there are no characters to consume.
             b_another = False
             continue
         #
         activity.mark(l=self, s='handling input')
         log('%s|%s|%s|%s|%s|%s|%s|%s' % (b0, b1, b2, b3, b4, b5, b6, b7))
         if b0 == 1:
             # Keystroke event. In this section we will translate [the
             # uint64_t that the api supplied] to a [solent-convention
             # keystroke enumeration that is suitable for the callback.]
             #
             # byte1: bitfield
             ks_bitfield = b1
             # byte2: windows-convention keystroke code that appeared in
             # a WM_KEYDOWN wParam.
             wink = b2
             #
             # unpack the bitfield into values we understand
             b_shift = False
             b_control = False
             n = 128
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 log("Warning. Unhandled bitfield value %s." % n)
             n = 64
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 log("Warning. Unhandled bitfield value %s." % n)
             n = 32
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 log("Warning. Unhandled bitfield value %s." % n)
             n = 16
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 log("Warning. Unhandled bitfield value %s." % n)
             n = 8
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 log("Warning. Unhandled bitfield value %s." % n)
             n = 4
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 log("Warning. Unhandled bitfield value %s." % n)
             n = 2
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 b_control = True
             n = 1
             if ks_bitfield >= n:
                 ks_bitfield -= n
                 b_shift = True
             #
             # arrow handling
             # 0-9 handling
             if wink >= 48 and wink <= 57:
                 # Source character relative to zero
                 zero_offset = wink - 48
                 # xxx Concerns:
                 # - We have no handling for ctrl+numbers at the moment. We
                 #   will want to add this in the future, but needs more
                 #   thought about what codes these translate to. At the
                 #   time of writing, I am tempted to have extension
                 #   characters that pop out the end of the 7-bit ascii
                 #   range, and into the second half of the 8-bit ascii
                 #   range. Mouseclicks could be relocated into this space.
                 # - We are not handling shift+numbers correctly here
                 #   either. There is an awkward keyboard-i18n angle to
                 #   this. For example, shift+2 means different things
                 #   between us-english and uk-english keyboards. Maybe
                 #   we will need to have the C API convey several bytes
                 #   through to us, representing different keycode
                 #   interpretations.
                 n = e_keycode.n0.value + zero_offset
                 #
                 k = e_keycode(n)
             # a-z handling
             elif wink >= 65 and wink <= 90:
                 # Source character relative to lower-case a
                 a_offset = wink - 65
                 if b_control:
                     n = e_keycode.lmousedown.value + a_offset
                 elif b_shift:
                     n = e_keycode.A.value + a_offset
                 else:
                     # Lower A is 97
                     n = e_keycode.a.value + a_offset
                 k = e_keycode(n)
             else:
                 # xxx
                 log("Unhandled %s" % (wink))
                 n = wink
                 #
                 k = e_keycode(n)
             #
             zero_h = self.spin_h
             self.call_windows_event_kevent(zero_h=zero_h, k=k)
         else:
             raise Exception('unhandled leading byte |%s|' % (b0))
Esempio n. 2
0
 def cb_selui_keycode(self, cs_selui_keycode):
     keycode = cs_selui_keycode.keycode
     #
     keycode = e_keycode(keycode)
     self.nearcast.keystroke(
         keycode=keycode)
Esempio n. 3
0
 def on_grid_kevent(self, keycode):
     log('received keycode |%s| {%s}' % (keycode, e_keycode(keycode)))
     #
     if keycode == e_keycode.Q:
         raise SolentQuitException()
     elif keycode == e_keycode.h:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop
         rest = shape_mob.rest - 1
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     elif keycode == e_keycode.j:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop + 1
         rest = shape_mob.rest
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     elif keycode == e_keycode.k:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop - 1
         rest = shape_mob.rest
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     elif keycode == e_keycode.l:
         shape_mob = self.track_mob.player
         mob_h = shape_mob.mob_h
         mtype = shape_mob.mtype
         drop = shape_mob.drop
         rest = shape_mob.rest + 1
         c = shape_mob.c
         cpair = shape_mob.cpair
         self.nearcast.mob_set(mob_h=mob_h,
                               mtype=mtype,
                               drop=drop,
                               rest=rest,
                               c=c,
                               cpair=cpair)
     #
     self.nearcast.render()