HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2020
0113
HSP 初心者HSP 画面外キー割り込み5解決


HSP 初心者

リンク

2020/1/13(Mon) 12:33:18|NO.89242

最近いろいろと質問してすみません。
今、キーを押すと音を鳴らすソフトを作っているのですが
キーコードの取得方法がわかりません。
onkeyだと画面外では使えないので
いい方法を教えてください。


#include "hgimg3.as" dmmini dmmload "key.wav",0 dmmload "key1.wav",1 dmmload "key2.wav",2 dmmload "key3.wav",3 dmmload "key4.wav",4 dmmload "key5.wav",5 dmmload "key6.wav",6 dmmload "key7.wav",7 dmmload "key8.wav",8 dmmload "key9.wav",9 title "keyaudio" *main getkey K8,8 if K8 = 1:dialog K8 getkey K9,9 if K9 = 1:gosub *lab getkey K10,10 if K10 = 1:gosub *lab getkey K11,11 if K11 = 1:gosub *lab getkey K12,12 if K12 = 1:gosub *lab getkey K13,13 if K13 = 1:gosub *lab getkey K14,14 if K14 = 1:gosub *lab getkey K15,15 if K15 = 1:gosub *lab getkey K16,16 if K16 = 1:gosub *lab getkey K17,17 if K17 = 1:gosub *lab getkey K18,18 if K18 = 1:gosub *lab getkey K19,19 if K19 = 1:gosub *lab getkey K20,20 if K20 = 1:gosub *lab getkey K21,21 if K21 = 1:gosub *lab getkey K22,22 if K22 = 1:gosub *lab getkey K23,23 if K23 = 1:gosub *lab getkey K24,24 if K24 = 1:gosub *lab getkey K25,25 if K25 = 1:gosub *lab getkey K26,26 if K26 = 1:gosub *lab getkey K27,27 if K27 = 1:gosub *lab getkey K28,28 if K28 = 1:gosub *lab getkey K29,29 if K29 = 1:gosub *lab getkey K30,30 if K30 = 1:gosub *lab getkey K31,31 if K31 = 1:gosub *lab getkey K32,32 if K32 = 1:gosub *lab getkey K33,33 if K33 = 1:gosub *lab getkey K34,34 if K34 = 1:gosub *lab getkey K35,35 if K35 = 1:gosub *lab getkey K36,36 if K36 = 1:gosub *lab getkey K37,37 if K37 = 1:gosub *lab getkey K38,38 if K38 = 1:gosub *lab getkey K39,39 if K39 = 1:gosub *lab getkey K40,40 if K40 = 1:gosub *lab getkey K41,41 if K41 = 1:gosub *lab getkey K42,42 if K42 = 1:gosub *lab getkey K43,43 if K43 = 1:gosub *lab getkey K44,44 if K44 = 1:gosub *lab getkey K45,45 if K45 = 1:gosub *lab getkey K46,46 if K46 = 1:gosub *lab getkey K47,47 if K47 = 1:gosub *lab getkey K48,48 if K48 = 1:gosub *lab getkey K49,49 if K49 = 1:gosub *lab getkey K50,50 if K50 = 1:gosub *lab getkey K51,51 if K51 = 1:gosub *lab getkey K52,52 if K52 = 1:gosub *lab getkey K53,53 if K53 = 1:gosub *lab getkey K54,54 if K54 = 1:gosub *lab getkey K55,55 if K55 = 1:gosub *lab getkey K56,56 if K56 = 1:gosub *lab getkey K57,57 if K57 = 1:gosub *lab getkey K58,58 if K58 = 1:gosub *lab getkey K59,59 if K59 = 1:gosub *lab getkey K60,60 if K60 = 1:gosub *lab getkey K61,61 if K61 = 1:gosub *lab getkey K62,62 if K62 = 1:gosub *lab getkey K63,63 if K63 = 1:gosub *lab getkey K64,64 if K64 = 1:gosub *lab getkey K65,65 if K65 = 1:gosub *lab getkey K66,66 if K66 = 1:gosub *lab getkey K67,67 if K67 = 1:gosub *lab getkey K68,68 if K68 = 1:gosub *lab getkey K69,69 if K69 = 1:gosub *lab getkey K70,70 if K70 = 1:gosub *lab getkey K71,71 if K71 = 1:gosub *lab getkey K72,72 if K72 = 1:gosub *lab getkey K73,73 if K73 = 1:gosub *lab getkey K74,74 if K74 = 1:gosub *lab getkey K75,75 if K75 = 1:gosub *lab getkey K76,76 if K76 = 1:gosub *lab getkey K77,77 if K77 = 1:gosub *lab getkey K78,78 if K78 = 1:gosub *lab getkey K79,79 if K79 = 1:gosub *lab getkey K80,80 if K80 = 1:gosub *lab getkey K81,81 if K81 = 1:gosub *lab getkey K82,82 if K82 = 1:gosub *lab getkey K83,83 if K83 = 1:gosub *lab getkey K84,84 if K84 = 1:gosub *lab getkey K85,85 if K85 = 1:gosub *lab getkey K86,86 if K86 = 1:gosub *lab getkey K87,87 if K87 = 1:gosub *lab getkey K88,88 if K88 = 1:gosub *lab getkey K89,89 if K89 = 1:gosub *lab getkey K90,90 if K90 = 1:gosub *lab getkey K91,91 if K91 = 1:gosub *lab getkey K92,92 if K92 = 1:gosub *lab getkey K93,93 if K93 = 1:gosub *lab getkey K94,94 if K94 = 1:gosub *lab getkey K95,95 if K95 = 1:gosub *lab getkey K96,96 if K96 = 1:gosub *lab getkey K97,97 if K97 = 1:gosub *lab getkey K98,98 if K98 = 1:gosub *lab getkey K99,99 if K99 = 1:gosub *lab getkey K100,100 if K100 = 1:gosub *lab getkey K101,101 if K101 = 1:gosub *lab getkey K102,102 if K102 = 1:gosub *lab getkey K103,103 if K103 = 1:gosub *lab getkey K104,104 if K104 = 1:gosub *lab getkey K105,105 if K105 = 1:gosub *lab getkey K106,106 if K106 = 1:gosub *lab getkey K107,107 if K107 = 1:gosub *lab getkey K108,108 if K108 = 1:gosub *lab getkey K109,109 if K109 = 1:gosub *lab getkey K110,110 if K110 = 1:gosub *lab getkey K111,111 if K111 = 1:gosub *lab getkey K112,112 if K112 = 1:gosub *lab getkey K113,113 if K113 = 1:gosub *lab getkey K114,114 if K114 = 1:gosub *lab getkey K115,115 if K115 = 1:gosub *lab getkey K116,116 if K116 = 1:gosub *lab getkey K117,117 if K117 = 1:gosub *lab getkey K118,118 if K118 = 1:gosub *lab getkey K119,119 if K119 = 1:gosub *lab getkey K120,120 if K120 = 1:gosub *lab getkey K121,121 if K121 = 1:gosub *lab getkey K122,122 if K122 = 1:gosub *lab getkey K123,123 if K123 = 1:gosub *lab getkey K124,124 if K124 = 1:gosub *lab getkey K125,125 if K125 = 1:gosub *lab getkey K126,126 if K126 = 1:gosub *lab getkey K127,127 if K127 = 1:gosub *lab getkey K128,128 if K128 = 1:gosub *lab getkey K129,129 if K129 = 1:gosub *lab getkey K130,130 if K130 = 1:gosub *lab getkey K131,131 if K131 = 1:gosub *lab getkey K132,132 if K132 = 1:gosub *lab getkey K133,133 if K133 = 1:gosub *lab getkey K134,134 if K134 = 1:gosub *lab getkey K135,135 if K135 = 1:gosub *lab getkey K136,136 if K136 = 1:gosub *lab getkey K137,137 if K137 = 1:gosub *lab getkey K138,138 if K138 = 1:gosub *lab getkey K139,139 if K139 = 1:gosub *lab getkey K140,140 if K140 = 1:gosub *lab getkey K141,141 if K141 = 1:gosub *lab getkey K142,142 if K142 = 1:gosub *lab getkey K143,143 if K143 = 1:gosub *lab getkey K144,144 if K144 = 1:gosub *lab getkey K145,145 if K145 = 1:gosub *lab getkey K146,146 if K146 = 1:gosub *lab getkey K147,147 if K147 = 1:gosub *lab getkey K148,148 if K148 = 1:gosub *lab getkey K149,149 if K149 = 1:gosub *lab getkey K150,150 if K150 = 1:gosub *lab getkey K151,151 if K151 = 1:gosub *lab getkey K152,152 if K152 = 1:gosub *lab getkey K153,153 if K153 = 1:gosub *lab getkey K154,154 if K154 = 1:gosub *lab getkey K155,155 if K155 = 1:gosub *lab getkey K156,156 if K156 = 1:gosub *lab getkey K157,157 if K157 = 1:gosub *lab getkey K158,158 if K158 = 1:gosub *lab getkey K159,159 if K159 = 1:gosub *lab getkey K160,160 if K160 = 1:gosub *lab getkey K161,161 if K161 = 1:gosub *lab getkey K162,162 if K162 = 1:gosub *lab getkey K163,163 if K163 = 1:gosub *lab getkey K164,164 if K164 = 1:gosub *lab getkey K165,165 if K165 = 1:gosub *lab getkey K166,166 if K166 = 1:gosub *lab getkey K167,167 if K167 = 1:gosub *lab getkey K168,168 if K168 = 1:gosub *lab getkey K169,169 if K169 = 1:gosub *lab getkey K170,170 if K170 = 1:gosub *lab getkey K171,171 if K171 = 1:gosub *lab getkey K172,172 if K172 = 1:gosub *lab getkey K173,173 if K173 = 1:gosub *lab getkey K174,174 if K174 = 1:gosub *lab getkey K175,175 if K175 = 1:gosub *lab getkey K176,176 if K176 = 1:gosub *lab getkey K177,177 if K177 = 1:gosub *lab getkey K178,178 if K178 = 1:gosub *lab getkey K179,179 if K179 = 1:gosub *lab getkey K180,180 if K180 = 1:gosub *lab getkey K181,181 if K181 = 1:gosub *lab getkey K182,182 if K182 = 1:gosub *lab getkey K183,183 if K183 = 1:gosub *lab getkey K184,184 if K184 = 1:gosub *lab getkey K185,185 if K185 = 1:gosub *lab getkey K186,186 if K186 = 1:gosub *lab getkey K187,187 if K187 = 1:gosub *lab getkey K188,188 if K188 = 1:gosub *lab getkey K189,189 if K189 = 1:gosub *lab getkey K190,190 if K190 = 1:gosub *lab getkey K191,191 if K191 = 1:gosub *lab getkey K192,192 if K192 = 1:gosub *lab getkey K193,193 if K193 = 1:gosub *lab getkey K194,194 if K194 = 1:gosub *lab getkey K195,195 if K195 = 1:gosub *lab getkey K196,196 if K196 = 1:gosub *lab getkey K197,197 if K197 = 1:gosub *lab getkey K198,198 if K198 = 1:gosub *lab getkey K199,199 if K199 = 1:gosub *lab getkey K200,200 if K200 = 1:gosub *lab getkey K201,201 if K201 = 1:gosub *lab getkey K202,202 if K202 = 1:gosub *lab getkey K203,203 if K203 = 1:gosub *lab getkey K204,204 if K204 = 1:gosub *lab getkey K205,205 if K205 = 1:gosub *lab getkey K206,206 if K206 = 1:gosub *lab getkey K207,207 if K207 = 1:gosub *lab getkey K208,208 if K208 = 1:gosub *lab getkey K209,209 if K209 = 1:gosub *lab getkey K210,210 if K210 = 1:gosub *lab getkey K211,211 if K211 = 1:gosub *lab getkey K212,212 if K212 = 1:gosub *lab getkey K213,213 if K213 = 1:gosub *lab getkey K214,214 if K214 = 1:gosub *lab getkey K215,215 if K215 = 1:gosub *lab getkey K216,216 if K216 = 1:gosub *lab getkey K217,217 if K217 = 1:gosub *lab getkey K218,218 if K218 = 1:gosub *lab getkey K219,219 if K219 = 1:gosub *lab getkey K220,220 if K220 = 1:gosub *lab getkey K221,221 if K221 = 1:gosub *lab getkey K222,222 if K222 = 1:gosub *lab getkey K223,223 if K223 = 1:gosub *lab getkey K224,224 if K224 = 1:gosub *lab getkey K225,225 if K225 = 1:gosub *lab getkey K226,226 if K226 = 1:gosub *lab getkey K227,227 if K227 = 1:gosub *lab getkey K228,228 if K228 = 1:gosub *lab getkey K229,229 if K229 = 1:gosub *lab getkey K230,230 if K230 = 1:gosub *lab getkey K231,231 if K231 = 1:gosub *lab getkey K232,232 if K232 = 1:gosub *lab getkey K233,233 if K233 = 1:gosub *lab getkey K234,234 if K234 = 1:gosub *lab getkey K235,235 if K235 = 1:gosub *lab getkey K236,236 if K236 = 1:gosub *lab getkey K237,237 if K237 = 1:gosub *lab getkey K238,238 if K238 = 1:gosub *lab getkey K239,239 if K239 = 1:gosub *lab getkey K240,240 if K240 = 1:gosub *lab getkey K241,241 if K241 = 1:gosub *lab getkey K242,242 if K242 = 1:gosub *lab getkey K243,243 if K243 = 1:gosub *lab getkey K244,244 if K244 = 1:gosub *lab getkey K245,245 if K245 = 1:gosub *lab getkey K246,246 if K246 = 1:gosub *lab getkey K247,247 if K247 = 1:gosub *lab getkey K248,248 if K248 = 1:gosub *lab getkey K249,249 if K249 = 1:gosub *lab getkey K250,250 if K250 = 1:gosub *lab getkey K251,251 if K251 = 1:gosub *lab getkey K252,252 if K252 = 1:gosub *lab getkey K253,253 if K253 = 1:gosub *lab getkey K254,254 if K254 = 1:gosub *lab getkey K255,255 if K255 = 1:gosub *lab loop stop *lab dmmplay rnd(10) goto *main stop



この記事に返信する


あらや

リンク

2020/1/13(Mon) 13:59:33|NO.89244

簡単な方法でよければこんなのはどうでしょうか

*main repeat 248, 8 getkey key, cnt if key : gosub *lab loop await 100 goto *main *lab mes "キーが押された" return



ほかの方法が良いなら、キーボードフックとかシステムフックを調べると何か出て来るかも



あらや

リンク

2020/1/13(Mon) 23:33:34|NO.89245

以前にマウスホイールをフックした時の物をキーフックに書き換えてみました。
http://hsp.tv/play/pforum.php?mode=pastwch&num=84110

おまけでキー名の取得も付けてみました。

#include "modclbk3.hsp" #define NULL 0 #define WH_KEYBOARD_LL 0x0000000D #define WM_KEYDOWN 0x00000100 #define WM_SYSKEYDOWN 0x00000104 #uselib "user32.dll" #cfunc SetWindowsHookEx "SetWindowsHookExA" int, sptr, int, int #func UnhookWindowsHookEx "UnhookWindowsHookEx" int #cfunc CallNextHookEx "CallNextHookEx" int, int, int, int #cfunc MapVirtualKey "MapVirtualKeyA" int,int // おまけで使用 #func GetKeyNameText "GetKeyNameTextA" int, var, int // おまけで使用 gkey = 0; // この変数にキー入力フラグを入れる /////////////////////////////////////////////////////////////////// sdim keyname, 64; // おまけ /////////////////////////////////////////////////////////////////// cbl = *LowLevelMouseProc; newclbk3 clbkptr, 3, cbl; hhook = SetWindowsHookEx( WH_KEYBOARD_LL, clbkptr, NULL, 0 ); // キー操作を感知した場合ウェイト中に割り込みが入る onexit goto *hookend; // 終了時にはフックを解放する *main redraw 0; color 255, 255, 255:boxf; color 0, 0, 0:pos 0, 0; if( gkey == 0 ) { mes "キーを押していない"; } else:if( gkey == 1 ) { mes "キーを押した\tキーコード:"+kcode+"\nキー名:"+keyname; } else:if( gkey == 2 ) { mes "キーを押し続けている\tキーコード:"+kcode+"\nキー名:"+keyname; } redraw 1; await 500; // 表示がわかりやすいように長めのウェイトにする goto *main; // フックのコールバック *LowLevelMouseProc dupptr Mstate, lparam, wparam*4, 4; // Mstate(0)=フックコード(nCode) Mstate(1)=メッセージ識別子(wParam) Mstate(2)=メッセージデータ(lParam) if( Mstate(0) < 0 ) { // フックコードが0未満の場合はフックを中止して制御を元に戻さなければいけない。 return CallNextHookEx( hhook, Mstate(0), Mstate(1), Mstate(2) ); } // ほとんどのキー入力はWM_KEYDOWNだが、ALTなどはWM_SYSKEYDOWNになる if( (Mstate(1) == WM_KEYDOWN) || (Mstate(1) == WM_SYSKEYDOWN) ) { dupptr lp, Mstate(2), 24, 4; // lParamはKBDLLHOOK構造体へのポインタが入っている(今回は不要) // lp(0)が仮想キーコード、lp(1)がハードウェアスキャンコード、lp(2)がキーの押しっぱなしなどの細かい情報群 // lp(3)はタイムスタンプ、lp(4)は追加情報(これは32ビットか64ビットかでサイズが変わる) kcode = lp(0); /////////////////////////////////////////////////////////////////// lp2 = MapVirtualKey( kcode, 0 ) << 16; // おまけでキー名取得 GetKeyNameText lp2, keyname, 64; // キー名取得本体 /////////////////////////////////////////////////////////////////// gkey = 1; // キーを押したかどうかだけ判定 } else { gkey = 0; /////////////////////////////////////////////////////////////////// sdim keyname, 64; // おまけを初期化 /////////////////////////////////////////////////////////////////// } return CallNextHookEx( hhook, Mstate(0), Mstate(1), Mstate(2) ); // フックしたデータをそのまま返す *hookend UnhookWindowsHookEx hhook; // フックの終了 end;



HSP 初心者

リンク

2020/1/14(Tue) 21:53:37|NO.89249

有難う御座います。
あとで試してみます



MillkeyStars

リンク

2020/1/15(Wed) 05:31:14|NO.89251

別のAPI での取得サンプル

#module _GeyKeyState #uselib "user32.dll" #cfunc _GetAsyncKeyState "GetAsyncKeyState" int #deffunc getkeyEx var p1,int p2 Val = _GetAsyncKeyState(p2) if (Val & 0x8000) : p1 = 1 : else : p1 = 0 return #global //以下サンプル : TAB キーを取得しています。 //キーが押された場合、タイトルバーの数字が 1 になります。 repeat 1000 await 100 getkeyEx Async,9 title ""+Async loop



HSP 初心者

リンク

2020/1/16(Thu) 13:55:27|NO.89257

返信ありがとうございます!
あらやさんのスクリプトを参考にして
できました。



ONION software Copyright 1997-2018(c) All rights reserved.