KeyHit() bug

Archives Forums/Blitz3D Bug Reports/KeyHit() bug

KillerX(Posted 2008) [#1]
When I use the function KeyHit(183) or WaitKey, it doesn't take input from Print Screen. The following keys also don't work: F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, Scroll Lock, Pause Break, or Num Lock. It also doesn't take the following keys on the num pad: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, and del.
It worked fine until I recently updated the compiler to version 1.99. Now those keys don't work.


jfk EO-11110(Posted 2008) [#2]
I guess you had a very old version before?
Anyway, I just made a test with blitz version 1.98, on a laptop without numpad. While PrnScrn in fact doesn't work, F1 to F12 works nicely, like all other keys that I tried. Try this:

While KeyHit(1)=0
For i=0 To 255
If KeyHit(i) Then Print i
Next
Wend

I have no idea why PrnScr doesn't work. Are you sure this worked with the old version?


KillerX(Posted 2008) [#3]
The other keys do work there. Print Screen still doesn't work. All of the keys don't work with when using Waitkey though.


Abrexxes(Posted 2008) [#4]
Only PrnScrn dont work here (simple win keyboard). I think this is a special case and is blocked by windows. (so the event is not send to your application).

cu


SytzeZ(Posted 2008) [#5]
I have the same problem with PauseBreak, but I use P instead of it now!
Blitz1.99


Dreamora(Posted 2008) [#6]
waitkey will never work, you are not using graphics.

It is already a wonder that keyhit works ... as a console has no event handling normally.

If you were talking of graphics windows, then sorry. I'm on 1.98 due to the stuff that gets broken with 1.99 on modern hardware and the like

print screen and the like won't work. Windows will react to them by putting the current screen content into the clipboard


KillerX(Posted 2008) [#7]
Print screen use to work. When I installed the compiler, it worked. But one I updated to version 1.99, it just stopped working.


Dreamora(Posted 2008) [#8]
1.64 is years old, back then Win95 and Win98 were standard.
The world changes and trash (win9x) is abandoned now :)

And I would suggest to remain on 1.98 ... 1.99 has done more bad than good to me.


_PJ_(Posted 2008) [#9]
Yeah PrintScreen/SystemRequest is funky.
I have also noticed some other sisues, such as Right-Alt returns as if two keys are pressed.

The following (which is part of a redefine-keys' function library highlights some of the weirdness discovered. The buggy values are either commented out or annotated:


Const KEY_NONE=0
Const KEY_ESCAPE=1
Const KEY_1=2
Const KEY_2=3
Const KEY_3=4
Const KEY_4=5
Const KEY_5=6
Const KEY_6=7
Const KEY_7=8
Const KEY_8=9
Const KEY_9=10
Const KEY_0=11
Const KEY_MINUS=12
Const KEY_PLUS=13
Const KEY_BACKSPACE=14
Const KEY_TAB=15
Const KEY_Q=16
Const KEY_W=17
Const KEY_E=18
Const KEY_R=19
Const KEY_T=20
Const KEY_Y=21
Const KEY_U=22
Const KEY_I=23
Const KEY_O=24
Const KEY_P=25
Const KEY_LEFTBRACKET=26
Const KEY_RIGHTBRACKET=27
Const KEY_RETURN=28
Const KEY_LCTRL=29
Const KEY_A=30
Const KEY_S=31
Const KEY_D=32
Const KEY_F=33
Const KEY_G=34
Const KEY_H=35
Const KEY_J=36
Const KEY_K=37
Const KEY_L=38
Const KEY_SEMICOLON=39
Const KEY_APOSTROPHE=40
Const KEY_TILDE=41
Const KEY_LSHIFT=42
Const KEY_HASH=43
Const KEY_Z=44
Const KEY_X=45
Const KEY_C=46
Const KEY_V=47
Const KEY_B=48
Const KEY_N=49
Const KEY_M=50
Const KEY_COMMA=51
Const KEY_FULLSTOP=52
Const KEY_SLASH=53
Const KEY_RSHIFT=54
Const KEY_NUM_ASTERISK=55
Const KEY_LALT=56
Const KEY_SPACEBAR=57
Const KEY_CAPSLOCK=58
Const KEY_FUNC_1=59
Const KEY_FUNC_2=60
Const KEY_FUNC_3=61
Const KEY_FUNC_4=62
Const KEY_FUNC_5=63
Const KEY_FUNC_6=64
Const KEY_FUNC_7=65
Const KEY_FUNC_8=66
Const KEY_FUNC_9=67
Const KEY_FUNC_10=68
Const KEY_PAUSE=69
Const KEY_SCROLL_LOCK=70
Const KEY_NUM_7=71
Const KEY_NUM_8=72
Const KEY_NUM_9=73
Const KEY_NUM_MINUS=74
Const KEY_NUM_4=75
Const KEY_NUM_5=76
Const KEY_NUM_6=77
Const KEY_NUM_PLUS=78
Const KEY_NUM_1=79
Const KEY_NUM_2=80
Const KEY_NUM_3=81
Const KEY_NUM_0=82
Const KEY_NUM_DEL=83
Const KEY_BAR=86
Const KEY_F11=87
Const KEY_F12=88
Const KEY_F13=100
Const KEY_F14=101
Const KEY_F15=102
Const KEY_KANA=112
Const KEY_ABNT_C1=115
Const KEY_CONVERT=121
Const KEY_NOCONVERT=123
Const KEY_YEN=125
Const KEY_EQUALS=141
Const KEY_MEDIA_PTRACK=144
Const KEY_AT=145
Const KEY_COLON=146
Const KEY_UNDERLINE=147
Const KEY_KANJI=148
Const KEY_MEDIA_STOP=149
Const KEY_AX=150
Const KEY_UNLABELED=151
Const KEY_MEDIA_NTRACK=153
Const KEY_NUM_ENTER=156
Const KEY_RCTRL=157
Const KEY_MEDIA_MUTE=160
Const KEY_MEDIA_CALC=161
Const KEY_MEDIA_PLAYPAUSE=162
Const KEY_MEDIA_QUIT=164
Const KEY_MEDIA_VOLDOWN=174
Const KEY_MEDIA_VOLUP=176
Const KEY_WEB_HOME=178
Const KEY_NUM_COMMA=179
Const KEY_NUM_SLASH=181
Const KEY_PRNTSCRN=183
Const KEY_RALT=184
Const KEY_NUMLOCK=197
Const KEY_HOME=199
Const KEY_UPARROW=200
Const KEY_PG_UP=201
Const KEY_LEFTARROW=203
Const KEY_RIGHTARROW=205
Const KEY_END=207
Const KEY_DOWNARROW=208
Const KEY_PG_DOWN=209
Const KEY_INSERT=210
Const KEY_DELETE=211
Const KEY_LMICROSOFTWIN=219
Const KEY_RMICROSOFTWIN=220
Const KEY_CONTEXT_MENU=221
Const KEY_POWER=222
Const KEY_SLEEP=223
Const KEY_WAKE=227
Const KEY_WEB_SRCH=229
Const KEY_WEB_FAVS=230
Const KEY_WEB_REFRESH=231
Const KEY_WEB_STOP=232
Const KEY_WEB_FWD=233
Const KEY_WEB_BCK=234
Const KEY_MYCOMP=235
Const KEY_MAIL=236
Const KEY_MEDIA=237

Const KEY_LEFT_MOUSE=238
Const KEY_RIGHT_MOUSE=239
Const KEY_MIDDLE_MOUSE=240
Const KEY_MOUSE_4=241
Const KEY_MOUSE_5=242
Const KEY_MOUSE_6=243
Const KEY_MOUSE_7=244

Const KEY_CONTROLLER_1=245
Const KEY_CONTROLLER_2=246
Const KEY_CONTROLLER_3=247
Const KEY_CONTROLLER_4=248
Const KEY_CONTROLLER_5=249
Const KEY_CONTROLLER_6=250
Const KEY_CONTROLLER_7=251
Const KEY_CONTROLLER_8=252
Const KEY_CONTROLLER_9=253
Const KEY_CONTROLLER_10=254
Const KEY_CONTROLLER_11=255
Const KEY_CONTROLLER_12=256
Const KEY_CONTROLLER_13=257
Const KEY_CONTROLLER_14=258
Const KEY_CONTROLLER_15=259
Const KEY_CONTROLLER_16=260
Const KEY_CONTROLLER_17=261
Const KEY_CONTROLLER_18=262
Const KEY_CONTROLLER_19=263
Const KEY_CONTROLLER_20=264

Const KEY_MOUSE_X=265
Const KEY_MOUSE_Y=266


Const KEY_CONTROLLER_X=268
Const KEY_CONTROLLER_Y=269
Const KEY_CONTROLLER_THROTTLE=270

Const KEY_CONTROLLER_HAT=271
Const KEY_CONTROLLER_A=272
Const KEY_CONTROLLER_B=273
Const KEY_CONTROLLER_C=274
Const KEY_CONTROLLER_D=275

Const KEY_CONTROLLER_X2=276
Const KEY_CONTROLLER_Y2=277

Const KEY_CONTROLLER_PITCH=278
Const KEY_CONTROLLER_YAW=279
Const KEY_CONTROLLER_ROLL=280


;******************************************************************************************************************
;******************************************************************************************************************
;	RETURN NAME IDENTIFIER OF CONTROL INPUT	VALUE	

	Function sGetKeyName$(nKey_Value)

		If nKey_Value<238		
			Select nKey_Value
				Case 0 Return ""
				Case 1 Return"ESCAPE"	
				Case 2 Return"1"	
				Case 3 Return"2"	
				Case 4 Return"3"	
				Case 5 Return"4"	
				Case 6 Return"5"	
				Case 7 Return"6"	
				Case 8 Return"7"	
				Case 9 Return"8"	
				Case 10 Return"9"	
				Case 11 Return"0"	
				Case 12 Return"MINUS"	
				Case 13 Return"PLUS"	
				Case 14 Return"BACKSPACE"	
				Case 15 Return"TAB"	
				Case 16 Return"Q"	
				Case 17 Return"W"	
				Case 18 Return"E"	
				Case 19 Return"R"	
				Case 20 Return"T"	
				Case 21 Return"Y"	
				Case 22 Return"U"	
				Case 23 Return"I"	
				Case 24 Return"O"	
				Case 25 Return"P"	
				Case 26 Return"LEFTBRACKET"	
				Case 27 Return"RIGHTBRACKET"	
				Case 28 Return"RETURN"	
				Case 29 Return"LCTRL"	
				Case 30 Return"A"	
				Case 31 Return"S"	
				Case 32 Return"D"	
				Case 33 Return"F"	
				Case 34 Return"G"	
				Case 35 Return"H"	
				Case 36 Return"J"	
				Case 37 Return"K"	
				Case 38 Return"L"	
				Case 39 Return"SEMICOLON"	
				Case 40 Return"APOSTROPHE"	
				Case 41 Return"TILDE"	
				Case 42 Return"LSHIFT"	
				Case 43 Return"HASH"	
				Case 44 Return"Z"	
				Case 45 Return"X"	
				Case 46 Return"C"	
				Case 47 Return"V"	
				Case 48 Return"B"	
				Case 49 Return"N"	
				Case 50 Return"M"	
				Case 51 Return"COMMA"	
				Case 52 Return"FULLSTOP"	
				Case 53 Return"SLASH"	
				Case 54 Return"RSHIFT"	
				Case 55 Return"NUM ASTERISK"	
				Case 56 Return"LALT"	
				Case 57 Return"SPACEBAR"	
				Case 58 Return"CAPSLOCK"	
				Case 59 Return"FUNC 1"	
				Case 60 Return"FUNC 2"	
				Case 61 Return"FUNC 3"	
				Case 62 Return"FUNC 4"	
				Case 63 Return"FUNC 5"	
				Case 64 Return"FUNC 6"	
				Case 65 Return"FUNC 7"	
				Case 66 Return"FUNC 8"	
				Case 67 Return"FUNC 9"	
				Case 68 Return"FUNC 10"	
				Case 69 Return"PAUSE"	
				Case 70 Return"SCROLL LOCK"	
				Case 71 Return"NUM 7"	
				Case 72 Return"NUM 8"	
				Case 73 Return"NUM 9"	
				Case 74 Return"NUM MINUS"	
				Case 75 Return"NUM 4"	
				Case 76 Return"NUM 5"	
				Case 77 Return"NUM 6"	
				Case 78 Return"NUM PLUS"	
				Case 79 Return"NUM 1"	
				Case 80 Return"NUM 2"	
				Case 81 Return"NUM 3"	
				Case 82 Return"NUM 0"	
				Case 83 Return"NUM DEL"	
				Case 86 Return"BAR"	
				Case 87 Return"F11"	
				Case 88 Return"F12"	
				;Case 100 Return"F13"	
				;Case 101 Return"F14"	
				;Case 102 Return"F15"	
				;Case 112 Return"KANA"	
				;Case 115 Return"ABNT C1"	
				;Case 121 Return"CONVERT"	
				;Case 123 Return"NOCONVERT"	
				;Case 125 Return"YEN"	
				;Case 126 Return"NUM DEL"	Used if Separate Decimal /Delete on NumPad
				Case 128 Return"MISC MEDIA CONTROL"
				;Case 141 Return"EQUALS"	
				;Case 144 Return"MEDIA PTRACK"	
				;Case 145 Return"AT"	
				;Case 146 Return"COLON"	
				;Case 147 Return"UNDERLINE"	
				;Case 148 Return"KANJI"	
				;Case 149 Return"MEDIA STOP"	
				;Case 150 Return"AX"	
				;Case 151 Return"UNLABELED"	
				;Case 153 Return"MEDIA NTRACK"	
				Case 156 Return"NUM ENTER"	
				Case 157 Return"RCTRL"	
				;Case 160 Return"MEDIA MUTE"	
				;Case 161 Return"MEDIA CALC"	
				;Case 162 Return"MEDIA PLAYPAUSE"	
				;Case 164 Return"MEDIA QUIT"	
				;Case 174 Return"MEDIA VOLDOWN"	
				;Case 176 Return"MEDIA VOLUP"	
				;Case 178 Return"WEB HOME"	
				;Case 179 Return"NUM COMMA"	
				Case 181 Return"NUM SLASH"	
				;Case 183 Return"PRNTSCRN"	
				Case 184 Return"RALT"	 ; 184 returns 29 also.
				Case 197 Return"NUMLOCK"	
				Case 199 Return"HOME"	
				Case 200 Return"UPARROW"	
				Case 201 Return"PG UP"	
				Case 203 Return"LEFTARROW"	
				Case 205 Return"RIGHTARROW"	
				Case 207 Return"END"	
				Case 208 Return"DOWNARROW"	
				Case 209 Return"PG DOWN"	
				Case 210 Return"INSERT"	
				Case 211 Return"DELETE"	
				Case 219 Return"LMICROSOFTWIN"	
				Case 220 Return"RMICROSOFTWIN"	
				Case 221 Return"CONTEXT MENU"	
				;Case 222 Return"POWER"	
				;Case 223 Return"SLEEP"	
				;Case 227 Return"WAKE"	
				;Case 229 Return"WEB SRCH"	
				;Case 230 Return"WEB FAVS"	
				;Case 231 Return"WEB REFRESH"	
				;Case 232 Return"WEB STOP"	
				;Case 233 Return"WEB FWD"	
				;Case 234 Return"WEB BCK"	
				;Case 235 Return"MYCOMP"	
				;Case 236 Return"MAIL"	
				;Case 237 Return"MEDIA"
			End Select
		End If
			Select nKey_Value
				Case 238 Return "LEFT MOUSE"
				Case 239 Return "RIGHT MOUSE"
				Case 240 Return "MIDDLE MOUSE"
				Case 241 Return "MOUSE 4"
				Case 242 Return "MOUSE 5"
				Case 243 Return "MOUSE 6"
				Case 244 Return "MOUSE 7"

				Case 245 Return "CONTROLLER 1"
				Case 246 Return "CONTROLLER 2"
				Case 247 Return "CONTROLLER 3"
				Case 248 Return "CONTROLLER 4"
				Case 249 Return "CONTROLLER 5"
				Case 250 Return "CONTROLLER 6"
				Case 251 Return "CONTROLLER 7"
				Case 252 Return "CONTROLLER 8"
				Case 253 Return "CONTROLLER 9"
				Case 254 Return "CONTROLLER 10"
				Case 255 Return "CONTROLLER 11"
				Case 256 Return "CONTROLLER 12"				
				Case 257 Return "CONTROLLER 13"
				Case 258 Return "CONTROLLER 14"
				Case 259 Return "CONTROLLER 15"				
				Case 260 Return "CONTROLLER 16"
				Case 261 Return "CONTROLLER 17"	
				Case 262 Return "CONTROLLER 18"	
				Case 263 Return "CONTROLLER 19"	
				Case 264 Return "CONTROLLER 20"	

				Case 265 Return "MOUSE X"
				Case 266 Return "MOUSE Y"
				Case 267 Return "MOUSEWHEEL"			
								
				Case 268 Return "CONTROLLER X"
				Case 269 Return "CONTROLLER Y"				
				Case 270 Return "CONTROLLER Z"
				
								
				Case 271 Return "CONTROLLER ^"			;; Use this ^ for ANALOGUE
				Case 272 Return "CONTROLLER ^1"			;; THE FOUR FOR DIGITAL	
				Case 273 Return "CONTROLLER ^2"			;; -----------------------
				Case 274 Return "CONTROLLER ^3"			;;------------------------
				Case 275 Return "CONTROLLER ^4"
				
				Case 276 Return "CONTROLLER X2"
				Case 277 Return "CONTROLLER Y2"				
				
				Case 278 Return "CONTROLLER PITCH"
				Case 279 Return "CONTROLLER YAW"
				Case 280 Return "CONTROLLER ROLL"
								
				Default Return "INVALID KEY"
			End Select
	End Function
;******************************************************************************************************************
;******************************************************************************************************************
;		RETURN VALUE OF CONTROL INPUT		************************************************************************
	Function nGetControlInput()
				;;THIS FUNCTION MUST BE LOOPED
					nReturn=0
								
					FlushKeys
					FlushMouse
					FlushJoy
			;	KEYBOARD KEY
					For f=0 To 237
						If KeyDown(f)		
							nReturn=f
							Exit
						EndIf
					Next
			;	MOUSE BUTTON	
					If (nReturn<1)
					
						For f=238 To 244
							nReturn=(f-237)
							If MouseDown(nReturn)		
								nReturn=f
								Exit
							EndIf
						Next
					EndIf
			;	CONTROLLER BUTTON	
					If (nReturn<1)
						For f=245 To 264
							nReturn=(f-244)
							If JoyDown(nReturn)		
								nReturn=f
								Exit
							EndIf
						Next
					EndIf	
			;	MOUSE / MOUSWHEEL	
					If (nReturn<1)
						If Abs(MouseXSpeed())>0.0 Then nReturn=265
						If Abs(MouseYSpeed())>0.0 Then nReturn=266
						If MouseZSpeed<>0 Then nReturn=267
					EndIf
			;	CONTROLLER X/Y AXES		
					If (nReturn<1)
						If Abs(Int(JoyX()))>0 Then nReturn=268
						If Abs(Int(JoyY()))>0 Then nReturn=269
					EndIf
			;	CONTROLLER U/V AXES	
					If (nReturn<1)
						If Abs(Int(JoyU()))>0 Then nReturn=276
						If Abs(Int(JoyV()))>0 Then nReturn=277
					EndIf
			;	CONTROLLER THROTTLE SLIDER		
					If (nReturn<1)
						If Abs(Int(JoyZ()))>0 Then nReturn=270
					EndIf
			;	HAT SWITCH

					
		Return nReturn
	
	End Function