Apply pressed keys on the 1d value
498935
function handle1dkeys (keys, value, step, min, max) {
	step = step || 1;

	//up and right - increase by one
	if (keys[38] || keys[39]) {
		value = inc(value, step, 1);
	}

	//down and left - decrease by one
	if (keys[40] || keys[37]) {
		value = inc(value, step, -1);
	}

	//home - min
	if (keys[36]) {
		value = min;
	}

	//end - max
	if (keys[35]) {
		value = max;
	}

	//pageup
	if (keys[33]) {
		value = inc(value, step, PAGE);
	}

	//pagedown
	if (keys[34]) {
		value = inc(value, step, -PAGE);
	}

	return value;
}
1080275
def _process_keystroke_movement(self, inp, idx, offset):
        """"""
        term = self.term
        if inp in (u'y', u'k') or inp.code in (term.KEY_UP,):
            # scroll backward 1 line
            idx, offset = (idx, offset - self.screen.num_columns)
        elif inp in (u'e', u'j') or inp.code in (term.KEY_ENTER,
                                                 term.KEY_DOWN,):
            # scroll forward 1 line
            idx, offset = (idx, offset + self.screen.num_columns)
        elif inp in (u'f', u' ') or inp.code in (term.KEY_PGDOWN,):
            # scroll forward 1 page
            idx, offset = (idx + 1, offset)
        elif inp == u'b' or inp.code in (term.KEY_PGUP,):
            # scroll backward 1 page
            idx, offset = (max(0, idx - 1), offset)
        elif inp.code in (term.KEY_SDOWN,):
            # scroll forward 10 pages
            idx, offset = (max(0, idx + 10), offset)
        elif inp.code in (term.KEY_SUP,):
            # scroll forward 10 pages
            idx, offset = (max(0, idx - 10), offset)
        elif inp.code == term.KEY_HOME:
            # top
            idx, offset = (0, 0)
        elif inp.code == term.KEY_END:
            # bottom
            idx, offset = (self.last_page, 0)
        return idx, offset
978511
def on_press(self, window, key, scancode, action, mods):
        

        # controls for moving position
        if key == glfw.KEY_W:
            self.pos[0] -= self._pos_step  # dec x
        elif key == glfw.KEY_S:
            self.pos[0] += self._pos_step  # inc x
        elif key == glfw.KEY_A:
            self.pos[1] -= self._pos_step  # dec y
        elif key == glfw.KEY_D:
            self.pos[1] += self._pos_step  # inc y
        elif key == glfw.KEY_F:
            self.pos[2] -= self._pos_step  # dec z
        elif key == glfw.KEY_R:
            self.pos[2] += self._pos_step  # inc z

        # controls for moving orientation
        elif key == glfw.KEY_Z:
            drot = rotation_matrix(angle=0.1, direction=[1., 0., 0.])[:3, :3]
            self.rotation = self.rotation.dot(drot)  # rotates x
        elif key == glfw.KEY_X:
            drot = rotation_matrix(angle=-0.1, direction=[1., 0., 0.])[:3, :3]
            self.rotation = self.rotation.dot(drot)  # rotates x
        elif key == glfw.KEY_T:
            drot = rotation_matrix(angle=0.1, direction=[0., 1., 0.])[:3, :3]
            self.rotation = self.rotation.dot(drot)  # rotates y
        elif key == glfw.KEY_G:
            drot = rotation_matrix(angle=-0.1, direction=[0., 1., 0.])[:3, :3]
            self.rotation = self.rotation.dot(drot)  # rotates y
        elif key == glfw.KEY_C:
            drot = rotation_matrix(angle=0.1, direction=[0., 0., 1.])[:3, :3]
            self.rotation = self.rotation.dot(drot)  # rotates z
        elif key == glfw.KEY_V:
            drot = rotation_matrix(angle=-0.1, direction=[0., 0., 1.])[:3, :3]
            self.rotation = self.rotation.dot(drot)
61807
def handle_input(self, ncode, wparam, lparam):
        """"""
        value = WIN_KEYBOARD_CODES[wparam]
        scan_code = lparam.contents.scan_code
        vk_code = lparam.contents.vk_code
        self.update_timeval()

        events = []
        # Add key event
        scan_key, key_event = self.emulate_press(
            vk_code, scan_code, value, self.timeval)
        events.append(scan_key)
        events.append(key_event)

        # End with a sync marker
        events.append(self.sync_marker(self.timeval))

        # We are done
        self.write_to_pipe(events)

        return ctypes.windll.user32.CallNextHookEx(
            self.hooked, ncode, wparam, lparam)
372106
function handleKeydown(keyCodes, e, callback) {
    const keyCode = e.charCode || e.keyCode;
    if (keyCodes.indexOf(keyCode) !== -1) {
        callback();
    }
}
102601
def key_press(self, key, x, y):
        ""
        if ord(key) == 27:
            # print "Escape!"
            if bool(glutLeaveMainLoop):
                glutLeaveMainLoop()
            else:
                raise Exception("Application quit")
1279833
def keyPressEvent(self, event):
        """"""
        if event.key() == Qt.Key_Delete:
            self.remove_item()
        elif event.key() == Qt.Key_F2:
            self.rename_item()
        elif event == QKeySequence.Copy:
            self.copy()
        elif event == QKeySequence.Paste:
            self.paste()
        else:
            QTableView.keyPressEvent(self, event)
962668
public void keyPressed(KeyEvent e) {
		int offset = (e.getKeyCode() == KeyEvent.VK_UP) ? (-7) : ((e
				.getKeyCode() == KeyEvent.VK_DOWN) ? (+7)
				: ((e.getKeyCode() == KeyEvent.VK_LEFT) ? (-1) : ((e
						.getKeyCode() == KeyEvent.VK_RIGHT) ? (+1) : 0)));

		int newDay = getDay() + offset;

		if ((newDay >= 1)
				&& (newDay <= calendar.getMaximum(Calendar.DAY_OF_MONTH))) {
			setDay(newDay);
		}
	}
1356378
def keyDown(self, keys):
        
        if not isinstance(keys, basestring):
            raise TypeError("keyDown expected keys to be a string")
        in_special_code = False
        special_code = ""
        for i in range(0, len(keys)):
            if keys[i] == "{":
                in_special_code = True
            elif in_special_code and (keys[i] == "}" or keys[i] == " " or i == len(keys)-1):
                # End of special code (or it wasn't a special code after all)
                in_special_code = False
                if special_code in self._SPECIAL_KEYCODES.keys():
                    # Found a special code
                    keyboard.press(self._SPECIAL_KEYCODES[special_code])
                else:
                    # Wasn't a special code, just treat it as keystrokes
                    self.keyDown("{")
                    # Press the rest of the keys normally
                    self.keyDown(special_code)
                    self.keyDown(keys[i])
                special_code = ""
            elif in_special_code:
                special_code += keys[i]
            elif keys[i] in self._REGULAR_KEYCODES.keys():
                keyboard.press(keys[i])
            elif keys[i] in self._UPPERCASE_KEYCODES.keys():
                keyboard.press(self._SPECIAL_KEYCODES["SHIFT"])
                keyboard.press(self._UPPERCASE_KEYCODES[keys[i]])
440184
function(d) {
    // return keyPosition if defined
    if (d.keyPosition !== undefined && d.keyPosition !== null)
      return d.keyPosition;
    // check if the dimension is the time dimension. Add it to the end of the key
    if (d.id === TIME_DIMENSION) return dimCount - 1;
    return null;
  }
516669
def get_keys_to_action(self):
        """"""
        # keyboard keys in an array ordered by their byte order in the bitmap
        # i.e. right = 7, left = 6, ..., B = 1, A = 0
        buttons = np.array([
            ord('d'),  # right
            ord('a'),  # left
            ord('s'),  # down
            ord('w'),  # up
            ord('\r'), # start
            ord(' '),  # select
            ord('p'),  # B
            ord('o'),  # A
        ])
        # the dictionary of key presses to controller codes
        keys_to_action = {}
        # the combination map of values for the controller
        values = 8 * [[0, 1]]
        # iterate over all the combinations
        for combination in itertools.product(*values):
            # unpack the tuple of bits into an integer
            byte = int(''.join(map(str, combination)), 2)
            # unwrap the pressed buttons based on the bitmap
            pressed = buttons[list(map(bool, combination))]
            # assign the pressed buttons to the output byte
            keys_to_action[tuple(sorted(pressed))] = byte

        return keys_to_action
863916
def keyEvent(self, key, down=1):
        """"""
        self.transport.write(pack("!BBxxI", 4, down, key))
877148
def buttons_pressed(self):
        
        for b in self._buffer_cache:
            fcntl.ioctl(self._button_file(b), self.EVIOCGKEY, self._buffer_cache[b])

        pressed = []
        for k, v in self._buttons.items():
            buf = self._buffer_cache[v['name']]
            bit = v['value']

            if bool(buf[int(bit / 8)] & 1 << bit % 8):
                pressed.append(k)

        return pressed
884884
def KeyPress(self, key, n=1, delay=0):
        
        self._delay(delay)
        cmd = Command("KeyPress", 'KeyPress "%s", %s' % (key, n))
        self.add(cmd)
796055
def increment(d, key, val=1):
    
    if key in d:
        d[key] += val
    else:
        d[key] = val
212992
def apply_move(grid, move):
    ""
    p, q = grid
    bit = 1 << move
    return (q, p | bit) if 0 == (bit & (p | q)) else None
1103799
def on_key_pressed(self, event):
        

        return

        # TODO

        if event.keysym == "Up":
            self.manager.set_joystick(0.0, -1.0, 0)
        elif event.keysym == "Down":
            self.manager.set_joystick(0.0, 1.0, 0)
        elif event.keysym == "Left":
            self.manager.set_joystick(-1.0, 0.0, 0)
        elif event.keysym == "Right":
            self.manager.set_joystick(1.0, 0.0, 0)

        elif event.char == " ":
            mode = self.manager.get_mode()
            if mode == self.manager.MODE_DISABLED:
                self.manager.set_mode(self.manager.MODE_OPERATOR_CONTROL)
            else:
                self.manager.set_mode(self.manager.MODE_DISABLED)