// 敵選択画面 int stage_choice(){ static int choice = 1; static int mode[GAME_MODE_NUM] = {{220}}; if(key_get(KEY_INPUT_LEFT) == 1){ choice --; }else if(key_get(KEY_INPUT_RIGHT) == 1){ choice ++; } if(choice < 1){ choice = GAME_MODE_NUM; }else if(choice > GAME_MODE_NUM){ choice = 1; } for(int i=0; i<GAME_MODE_NUM; i++){ mode[i] = 220; } mode[choice - 1] = 210; DrawString(300, mode[0], "1", GetColor(255, 0 ,0)); DrawString(320, mode[1], "2", GetColor(0, 255, 0)); DrawString(340, mode[2], "3", GetColor(0, 0, 255)); if(key_get(KEY_INPUT_RETURN) == 1){ return choice; choice = 0; }else { return 0; } }
/*! * @brief 检测key状态(带延时消抖) * @param KEY_e KEY编号 * @return KEY_STATUS_e KEY状态(KEY_DOWN、KEY_DOWN) * @since v5.0 * Sample usage: if(key_check(KEY_U) == KEY_DOWN) { printf("\n按键按下") } */ KEY_STATUS_e key_check(KEY_e key) { if(key_get(key) == KEY_DOWN) { DELAY_MS(10); if( key_get(key) == KEY_DOWN) { return KEY_DOWN; } } return KEY_UP; }
void hamlib_init() { int status; if (no_trx_control == 1) { trx_control = 0; } if (trx_control != 0) { shownr("Rignumber is", (int) myrig_model); shownr("Rig speed is", serial_rate); showmsg("Trying to start rig ctrl"); status = init_tlf_rig(); if (status != 0) { showmsg("Continue without rig control Y/(N)?"); if (toupper(key_get()) != 'Y') { endwin(); exit(1); } trx_control = 0; showmsg("Disabling rig control!"); sleep(1); } } }
/* * This is the task which runs the usermode application */ static int ____call_usermodehelper(void *data) { struct subprocess_info *sub_info = data; struct key *new_session, *old_session; int retval; /* Unblock all signals and set the session keyring. */ new_session = key_get(sub_info->ring); flush_signals(current); spin_lock_irq(¤t->sighand->siglock); old_session = __install_session_keyring(current, new_session); flush_signal_handlers(current, 1); sigemptyset(¤t->blocked); recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); key_put(old_session); /* We can run anywhere, unlike our parent keventd(). */ set_cpus_allowed(current, CPU_MASK_ALL); retval = -EPERM; if (current->fs->root) retval = execve(sub_info->path, sub_info->argv,sub_info->envp); /* Exec failed? */ sub_info->retval = retval; do_exit(0); }
/* * instantiate a request-key authorisation record */ static int request_key_auth_instantiate(struct key *key, const void *data, size_t datalen) { struct request_key_auth *rka, *irka; struct key *instkey; int ret; ret = -ENOMEM; rka = kmalloc(sizeof(*rka), GFP_KERNEL); if (rka) { /* see if the calling process is already servicing the key * request of another process */ instkey = key_get_instantiation_authkey(0); if (!IS_ERR(instkey)) { /* it is - use that instantiation context here too */ irka = instkey->payload.data; rka->context = irka->context; rka->pid = irka->pid; key_put(instkey); } else { /* it isn't - use this process as the context */ rka->context = current; rka->pid = current->pid; } rka->target_key = key_get((struct key *) data); key->payload.data = rka; ret = 0; } return ret; } /* end request_key_auth_instantiate() */
/* * Call a usermode helper with a specific session keyring. */ static int call_usermodehelper_keys(char *path, char **argv, char **envp, struct key *session_keyring, int wait) { return call_usermodehelper_fns(path, argv, envp, wait, umh_keys_init, umh_keys_cleanup, key_get(session_keyring)); }
static void test_upgrade_key(CuTest *tc) { attrib *alist = 0; key_set_orig(&alist, 40); key_set_orig(&alist, 41); key_set_orig(&alist, 43); key_set_orig(&alist, 42); key_set_orig(&alist, 44); CuAssertPtrNotNull(tc, alist->type->upgrade); alist->type->upgrade(&alist, alist); CuAssertIntEquals(tc, 1, key_get(alist, 40)); CuAssertIntEquals(tc, 1, key_get(alist, 41)); CuAssertIntEquals(tc, 1, key_get(alist, 42)); CuAssertIntEquals(tc, 1, key_get(alist, 43)); CuAssertIntEquals(tc, 1, key_get(alist, 44)); a_removeall(&alist, NULL); }
/** allow control of bandmap features */ void bm_menu() { int curx, cury; char c = -1; int j; getyx( stdscr, cury, curx); /* remember cursor */ attrset( COLOR_PAIR(C_LOG) | A_STANDOUT ); mvprintw( 13, 0, " Toggle <B>and, <M>ode or <D>upes filter"); printw(" | any other - leave"); c = toupper( key_get()); switch (c) { case 'B': bm_config.allband = 1 - bm_config.allband; break; case 'M': bm_config.allmode = 1 - bm_config.allmode; break; case 'D': bm_config.showdupes = 1 - bm_config.showdupes; break; } bandmap_show(); /* refresh display */ move (13,0); for (j = 0; j < 80; j++) addch (' '); move (cury, curx); refreshp(); }
void delete_qso(void) { int x; struct stat statbuf; int lfile; char logline[100]; char call[15], bandmode[6]; mvprintw(13, 29, "OK to delete last qso (y/n)?"); x = key_get(); if ((x == 'y') || (x == 'Y')) { if ((lfile = open(logfile, O_RDWR)) < 0) { TLF_LOG_WARN("I can not find the logfile..."); } else { fstat(lfile, &statbuf); if (statbuf.st_size >= LOGLINELEN) { if (qtcdirection > 0) { // read band, mode and call from last QSO line lseek(lfile, ((int)statbuf.st_size - LOGLINELEN), SEEK_SET); IGNORE(read(lfile, logline, LOGLINELEN - 1));; g_strlcpy(bandmode, logline, 6); g_strlcpy(call, logline + 29, 15); g_strchomp(call); // delete QTC's for that combination of band, mode and call delete_last_qtcs(call, bandmode); } IGNORE(ftruncate(lfile, statbuf.st_size - LOGLINELEN)); } fsync(lfile); close(lfile); if (qsos[nr_qsos][0] != ';') { band_score[bandinx]--; qsonum--; qsonr_to_str(); } nr_qsos--; qsos[nr_qsos][0] = '\0'; } scroll_log(); } attron(COLOR_PAIR(C_LOG) | A_STANDOUT); mvprintw(13, 29, " "); printcall(); clear_display(); }
// FX0A: A key press is awaited, and then stored in VX static int op_FX0A(word_t op) { int x = (op >> 8) & 0xF; chip8.V[x] = key_get(); return SUCCESS; }
static int tolua_region_getkey(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); int flag = atoi36(name); lua_pushboolean(L, key_get(self->attribs, flag)); return 1; }
/* * Call out to userspace for key construction. * * Program failure is ignored in favour of key status. */ static int construct_key(struct key *key, const void *callout_info, size_t callout_len, void *aux, struct key *dest_keyring) { struct key_construction *cons; request_key_actor_t actor; struct key *authkey; int ret; kenter("%d,%p,%zu,%p", key->serial, callout_info, callout_len, aux); cons = kmalloc(sizeof(*cons), GFP_KERNEL); if (!cons) return -ENOMEM; /* allocate an authorisation key */ authkey = request_key_auth_new(key, callout_info, callout_len, dest_keyring); if (IS_ERR(authkey)) { kfree(cons); ret = PTR_ERR(authkey); authkey = NULL; } else { cons->authkey = key_get(authkey); cons->key = key_get(key); /* make the call */ actor = call_sbin_request_key; if (key->type->request_key) actor = key->type->request_key; ret = actor(cons, "create", aux); /* check that the actor called complete_request_key() prior to * returning an error */ WARN_ON(ret < 0 && !test_bit(KEY_FLAG_REVOKED, &authkey->flags)); key_put(authkey); } kleave(" = %d", ret); return ret; }
/*! * @brief 定时检测key状态 * @since v5.0 * @note 此函数需要放入 定时中断复位函数里,定时10ms执行一次 */ void key_IRQHandler(void) { KEY_e keynum; static uint8 keytime[KEY_MAX]; //静态数组,保存各数组按下时间 KEY_MSG_t keymsg; //按键消息 for(keynum = (KEY_e)0 ; keynum < KEY_MAX; keynum ++) //每个按键轮询 { if(key_get(keynum) == KEY_DOWN) //判断按键是否按下 { keytime[keynum]++; //按下时间累加 if(keytime[keynum] <= KEY_DOWN_TIME) //判断时间是否没超过消抖确认按下时间 { continue; //没达到,则继续等待 } else if(keytime[keynum] == KEY_DOWN_TIME + 1 ) //判断时间是否为消抖确认按下时间 { //确认按键按下 keymsg.key = keynum; keymsg.status = KEY_DOWN; send_key_msg(keymsg); //把按键值和按键类型发送消息到FIFO } else if(keytime[keynum] <= KEY_HOLD_TIME) //是否没超过长按HOLD按键确认时间 { continue; //没超过,则继续等待 } else if(keytime[keynum] == KEY_HOLD_TIME + 1) //是否为长按hold确认时间 { //确认长按HOLD keymsg.key = keynum; keymsg.status = KEY_HOLD; send_key_msg(keymsg); //发送 keytime[keynum] = KEY_DOWN_TIME + 1; } else { keytime[keynum] = KEY_DOWN_TIME + 1; //继续重复检测 hold 状态 } } else { if(keytime[keynum] > KEY_DOWN_TIME) //如果确认过按下按键 { keymsg.key = keynum; keymsg.status = KEY_UP; send_key_msg(keymsg); //发送按键弹起消息 } keytime[keynum] = 0; //时间累计清0 } } }
static void test_upgrade_dict(CuTest *tc) { attrib *a; a = a_new(&at_dict); dict_set(a, "embassy_muschel", 42); CuAssertPtrNotNull(tc, a->type->upgrade); a->type->upgrade(&a, a); CuAssertIntEquals(tc, 42, key_get(a, atoi36("mupL"))); a_removeall(&a, NULL); }
/** * call_usermodehelper_setkeys - set the session keys for usermode helper * @info: a subprocess_info returned by call_usermodehelper_setup * @session_keyring: the session keyring for the process */ void call_usermodehelper_setkeys(struct subprocess_info *info, struct key *session_keyring) { #ifdef CONFIG_KEYS struct thread_group_cred *tgcred = info->cred->tgcred; key_put(tgcred->session_keyring); tgcred->session_keyring = key_get(session_keyring); #else BUG(); #endif }
/* * bind a key with a ctx together. * caller must hold write lock of the key, as well as ref on key & ctx. */ static void bind_key_ctx(struct key *key, struct ptlrpc_cli_ctx *ctx) { LASSERT(atomic_read(&ctx->cc_refcount) > 0); LASSERT(atomic_read(&key->usage) > 0); LASSERT(ctx2gctx_keyring(ctx)->gck_key == NULL); LASSERT(key->payload.data == NULL); /* at this time context may or may not in list. */ key_get(key); atomic_inc(&ctx->cc_refcount); ctx2gctx_keyring(ctx)->gck_key = key; key->payload.data = ctx; }
/* poll keyboard and update lcd */ void lcdterm_tick(void) { uint8_t k; if (!active) return; k = key_get(); if (k != lastkey) { lastkey = k; if (alt) /* apply alt */ k = alter(k); else /* apply caps lock */ if (capslock) { if(k >= 'a' && k <= 'z') k = (k-'a') + 'A'; } /* handle special/mode keys */ switch(k) { case KCAP: capslock = !capslock; lcdterm_cursor(); return; case KALT: alt = !alt; lcdterm_cursor(); return; case KSPK: case KPWR: case KMNU: case KONL: case KDWN: case KBYE: return; } /* feed console */ if (0 != k) { if (console_rx_ready_callback()) console_rx_callback(k); } } }
/* * copy the keys for fork */ int copy_keys(unsigned long clone_flags, struct task_struct *tsk) { key_check(tsk->thread_keyring); key_check(tsk->request_key_auth); /* no thread keyring yet */ tsk->thread_keyring = NULL; /* copy the request_key() authorisation for this thread */ key_get(tsk->request_key_auth); return 0; } /* end copy_keys() */
/* * Call a usermode helper with a specific session keyring. */ static int call_usermodehelper_keys(char *path, char **argv, char **envp, struct key *session_keyring, enum umh_wait wait) { gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; struct subprocess_info *info = call_usermodehelper_setup(path, argv, envp, gfp_mask); if (!info) return -ENOMEM; call_usermodehelper_setfns(info, umh_keys_init, umh_keys_cleanup, key_get(session_keyring)); return call_usermodehelper_exec(info, wait); }
/* * link a key to the appropriate destination keyring * - the caller must hold a write lock on the destination keyring */ static void construct_key_make_link(struct key *key, struct key *dest_keyring) { struct task_struct *tsk = current; struct key *drop = NULL; kenter("{%d},%p", key->serial, dest_keyring); /* find the appropriate keyring */ if (!dest_keyring) { switch (tsk->jit_keyring) { case KEY_REQKEY_DEFL_DEFAULT: case KEY_REQKEY_DEFL_THREAD_KEYRING: dest_keyring = tsk->thread_keyring; if (dest_keyring) break; case KEY_REQKEY_DEFL_PROCESS_KEYRING: dest_keyring = tsk->signal->process_keyring; if (dest_keyring) break; case KEY_REQKEY_DEFL_SESSION_KEYRING: rcu_read_lock(); dest_keyring = key_get( rcu_dereference(tsk->signal->session_keyring)); rcu_read_unlock(); drop = dest_keyring; if (dest_keyring) break; case KEY_REQKEY_DEFL_USER_SESSION_KEYRING: dest_keyring = tsk->user->session_keyring; break; case KEY_REQKEY_DEFL_USER_KEYRING: dest_keyring = tsk->user->uid_keyring; break; case KEY_REQKEY_DEFL_GROUP_KEYRING: default: BUG(); } } /* and attach the key to it */ __key_link(dest_keyring, key); key_put(drop); kleave(""); }
/* * given a ctx, unbind with its coupled key, if any. * unbind could only be called once, so we don't worry the key be released * by someone else. */ static void unbind_ctx_kr(struct ptlrpc_cli_ctx *ctx) { struct key *key = ctx2gctx_keyring(ctx)->gck_key; if (key) { LASSERT(key->payload.data == ctx); key_get(key); down_write(&key->sem); unbind_key_ctx(key, ctx); up_write(&key->sem); key_put(key); } }
/* * Call a usermode helper with a specific session keyring. */ static int call_usermodehelper_keys(char *path, char **argv, char **envp, struct key *session_keyring, int wait) { struct subprocess_info *info; info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL, umh_keys_init, umh_keys_cleanup, session_keyring); if (!info) return -ENOMEM; key_get(session_keyring); return call_usermodehelper_exec(info, wait); }
// タイトル画面 int title(){ static int choice = 1; static int strX[TITLE_MODE_NUM] = {{350}}; static int titleGraph = LoadGraph("素材\\ドット絵\\その他\\アクションミニゲーム表紙.jpg"); if(key_get(KEY_INPUT_UP) == 1){ choice --; }else if(key_get(KEY_INPUT_DOWN) == 1){ choice ++; } if(choice < 1){ choice = TITLE_MODE_NUM; }else if(choice > TITLE_MODE_NUM){ choice = 1; } for(int i=0; i<TITLE_MODE_NUM; i++){ strX[i] = 340; } strX[choice - 1] = 300; DrawGraph(0, 0, titleGraph, TRUE); SetFontSize(20); DrawString(strX[0], 250, "GAMESTART", GetColor(255, 0 ,0)); DrawString(strX[1], 270, "PUZZLE", GetColor(0, 255 ,0)); DrawString(strX[2], 290, "EXIT ", GetColor(0, 0, 255)); //DrawCircle(285, 236 + 20 * choice, 10, GetColor(100, 100, 100), TRUE); if(key_get(KEY_INPUT_Z) == 1){ return choice; choice = 1; }else { return 0; } }
/* * copy the keys in a thread group for fork without CLONE_THREAD */ int copy_thread_group_keys(struct task_struct *tsk) { key_check(current->thread_group->session_keyring); key_check(current->thread_group->process_keyring); /* no process keyring yet */ tsk->signal->process_keyring = NULL; /* same session keyring */ rcu_read_lock(); tsk->signal->session_keyring = key_get(rcu_dereference(current->signal->session_keyring)); rcu_read_unlock(); return 0; } /* end copy_thread_group_keys() */
static void test_group_readwrite(CuTest * tc) { faction * f; group *g; ally *al; int i; gamedata data; storage store; test_cleanup(); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); f = test_create_faction(0); new_group(f, "NW", 42); g = new_group(f, "Egoisten", 43); key_set(&g->attribs, 44); al = ally_add(&g->allies, f); al->status = HELP_GIVE; write_groups(&store, f); WRITE_INT(&store, 47); free_group(f->groups); free_group(g); f->groups = 0; data.strm.api->rewind(data.strm.handle); read_groups(&data, f); READ_INT(&store, &i); mstream_done(&data.strm); gamedata_done(&data); CuAssertIntEquals(tc, 47, i); CuAssertPtrNotNull(tc, f->groups); CuAssertIntEquals(tc, 42, f->groups->gid); CuAssertStrEquals(tc, "NW", f->groups->name); CuAssertPtrNotNull(tc, f->groups->next); CuAssertIntEquals(tc, 43, f->groups->next->gid); CuAssertStrEquals(tc, "Egoisten", f->groups->next->name); CuAssertPtrEquals(tc, 0, f->groups->allies); g = f->groups->next; CuAssertTrue(tc, key_get(g->attribs, 44)); CuAssertPtrNotNull(tc, g->allies); CuAssertPtrEquals(tc, 0, g->allies->next); CuAssertPtrEquals(tc, f, g->allies->faction); CuAssertIntEquals(tc, HELP_GIVE, g->allies->status); test_cleanup(); }
static void get_keys(const char *suffix) { if (key_get(type, suffix, &ks) < 0) fail("key_get failed"); if (ks.pub_avail < 0) fail("no public key available"); if (ks.priv_avail < 0) fail("no private key available"); if (ecdsa_set_curve(ks.ctype) < 0) fail("ecdsa_set_curve failed"); ecdsa_set_pub(ks.pub); ecdsa_set_priv(ks.priv); }
/* * copy the keys in a thread group for fork without CLONE_THREAD */ int copy_thread_group_keys(struct task_struct *tsk) { unsigned long flags; key_check(current->thread_group->session_keyring); key_check(current->thread_group->process_keyring); /* no process keyring yet */ tsk->signal->process_keyring = NULL; /* same session keyring */ spin_lock_irqsave(¤t->sighand->siglock, flags); tsk->signal->session_keyring = key_get(current->signal->session_keyring); spin_unlock_irqrestore(¤t->sighand->siglock, flags); return 0; } /* end copy_thread_group_keys() */
static void test_get_set_keys(CuTest *tc) { attrib *a = 0; key_set(&a, 42); key_set(&a, 43); key_set(&a, 44); CuAssertTrue(tc, key_get(a, 42)); CuAssertTrue(tc, key_get(a, 43)); CuAssertTrue(tc, key_get(a, 44)); key_unset(&a, 42); CuAssertTrue(tc, !key_get(a, 42)); CuAssertTrue(tc, key_get(a, 43)); CuAssertTrue(tc, key_get(a, 44)); a_removeall(&a, NULL); }
static void test_get_set_keys(CuTest *tc) { attrib *a = 0; key_set(&a, 42, 1); key_set(&a, 43, 2); key_set(&a, 44, 3); CuAssertIntEquals(tc, 1, key_get(a, 42)); CuAssertIntEquals(tc, 2, key_get(a, 43)); CuAssertIntEquals(tc, 3, key_get(a, 44)); key_unset(&a, 42); CuAssertIntEquals(tc, 0, key_get(a, 42)); CuAssertIntEquals(tc, 2, key_get(a, 43)); CuAssertIntEquals(tc, 3, key_get(a, 44)); a_removeall(&a, NULL); }
struct key *afs_request_key(struct afs_cell *cell) { struct key *key; _enter("{%x}", key_serial(cell->anonymous_key)); _debug("key %s", cell->anonymous_key->description); key = request_key(&key_type_rxrpc, cell->anonymous_key->description, NULL); if (IS_ERR(key)) { if (PTR_ERR(key) != -ENOKEY) { _leave(" = %ld", PTR_ERR(key)); return key; } _leave(" = {%x} [anon]", key_serial(cell->anonymous_key)); return key_get(cell->anonymous_key); } else { _leave(" = {%x} [auth]", key_serial(key)); return key; } }