Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 483
» Latest member: aplus
» Forum threads: 2,799
» Forum posts: 26,380
Full Statistics
|
|
|
Thinking about updating _KEYHIT in the wiki... |
Posted by: Pete - 08-17-2024, 02:12 AM - Forum: Works in Progress
- No Replies
|
 |
Code: (Select All)
Dim x, oldx(3) As Long
Dim i, cnt, cy, cx As Integer
Screen _NewImage(800, 600, 8)
Cls
font = _LoadFont("cyberbit.ttf", 24)
unifont = _LoadFont("cyberbit.ttf", 24, "UNICODE")
_Font font
Do
x = _KeyHit
If x And x <> oldx(1) And x <> oldx(2) And x <> oldx(3) Then
Select Case x
Case Is > 0
Color 10
Print "Pressed "; ' Positive value means key was pressed.
cnt = cnt + 1 ' Tracking on.
oldx(cnt) = x
Case Else ' Negative value means key was released.
Color 2
Print "Released ";
x = -x
i = 0: Do ' Tracking off.
i = i + 1
If oldx(i) = x Then cnt = cnt - 1: oldx(i) = 0: Exit Do
Loop Until i = 3
End Select
Select Case x
Case Is < 256
If x < 256 Then ' ASCII code values.
Print "ASCII "; x;
If x >= 32 And x <= 255 Then Print "[" + Chr$(x) + "]" Else Print
End If
Case 256 To 65536 ' 2 byte key codes.
Print "2-BYTE-COMBO "; x And 255; x \ 256;
x2 = x \ 256
If x2 >= 32 And x2 <= 255 Then Print "[" + Chr$(x2) + "]" Else Print
Case 100000 To 199999 ' QB64 Virtual Key codes.
Print "SDL VK"; x - 100000
Case 200000 To &H3FFFFFFF
Print "QB64 VK"; x - 200000
Case Is >= &H40000000 ' Unicode values. (IME Input mode)
Print "UNICODE "; x - &H40000000; "0x" + Hex$(x - &H40000000) + " ...";
cx = Pos(1): cy = CsrLin
_Font unifont
Locate cy, cx
Color 15
z$ = MKL$(x - &H40000000) + MKL$(0)
Print z$ + z$ + z$;
_Font font
Locate cy, 1: Print
End Select
End If
Loop
This modification of the existing version adds tracking the keys so it only prints to the screen once, allowing us to hold down key combinations without the screen scrolling all over hell and half of Georgia. (I've always wondered what half of Georgia that is?)
What I don't get is how to test the unicode case. I'm using a standard laptop keyboard. Any ideas???
Interesting that there are some keys that won't allow a 3 key press like A+S+W. The W will not register. That's probably because those keys are sometimes involved in arrow directions.
Since this would be for the wiki, I'm open to any suggestions, modifications, etc. but I get it, wiki examples should be as short and to the point as possible. Prettying things up is the readers responsibility.
Pete
|
|
|
I also have a question - about DefInt |
Posted by: PhilOfPerth - 08-16-2024, 11:33 PM - Forum: Help Me!
- Replies (4)
|
 |
While youse guys are studying cause and effect, I've been experimenting with the DefInt function, and I don't understand the results.
The DefInt function truncates all variables of that name to their integer values, and they then operate with this integer value, right?
But why do I get the Inf result in this snippet? I guess it's to do with their binary expression?
t1 and t2 are "simple" integers aren't they?
Code: (Select All) DefInt T
t1 = Timer
Print "T1 is integer. ", , , t1
Sleep 2
ActOnT
Sub ActOnT
t2 = Timer
Print "t2 is integer in sub. ", , , t2
t3 = t1 / t2
Print "t3 is result of t1 divided by t2, I expect 0. ", t1 / t2
t4 = t2 / t1
Print "t4 is result of t2 divided by t1, I expect 1. ", t2 / t1
End Sub
|
|
|
ON ERROR question |
Posted by: TerryRitchie - 08-16-2024, 07:16 PM - Forum: Help Me!
- Replies (18)
|
 |
I noticed that ON ERROR line labels can't be placed within subroutines:
SUB MySub()
ON ERROR GOTO ErrHandler
... code
ErrHandler:
END SUB
Is this normal? I'm using QB64pe v3.13.1
The Wiki states ON ERROR can be used in Subs/Functions but no mention of label being required to be outside of the Sub/Function.
|
|
|
undocumented Len function |
Posted by: Jack - 08-16-2024, 03:39 PM - Forum: General Discussion
- Replies (3)
|
 |
in the Wiki the Len function is described for strings only but QBasic uses the Len function also to get the size in bytes of data types including udts
but QB64pe also gives the size in bytes of an array, but this seems to be a feature and it behaves strangely
the following works and prints 50, 100 and 200
Code: (Select All)
Dim As Integer i(4, 4)
Dim As Long l(4, 4)
Dim As _Integer64 ll(4, 4)
Print Len(i())
Print Len(l())
Print Len(ll())
but if you add the following
Code: (Select All)
Print Len(l()) / Len(i())
it prints 100 instead of 2, the division never takes place
I think that getting the SizeOf an array would be nice to have and it almost works, perhaps the developers could fix it so that the last statement would be evaluated correctly
|
|
|
double error |
Posted by: Jack - 08-16-2024, 11:19 AM - Forum: General Discussion
- Replies (1)
|
 |
this is only an example of accumulated errors in double floating-point
Code: (Select All)
_Title "MatMul"
$Console:Only
_Dest _Console
Dim As Double a(3, 3), b(3, 3), c(3, 3), d(3, 3)
Dim As Long i
a(0, 0) = 1#: a(0, 1) = 1#: a(0, 2) = 1#: a(0, 3) = 1#
a(1, 0) = 2#: a(1, 1) = 4#: a(1, 2) = 8#: a(1, 3) = 16#
a(2, 0) = 3#: a(2, 1) = 9#: a(2, 2) = 27#: a(2, 3) = 81#
a(3, 0) = 4#: a(3, 1) = 16#: a(3, 2) = 64#: a(3, 3) = 256#
'b() = Inverse of a()
b(0, 0) = 4#: b(0, 1) = -3#: b(0, 2) = 4 / 3#: b(0, 3) = -1 / 4#
b(1, 0) = -13 / 3#: b(1, 1) = 19 / 4#: b(1, 2) = -7 / 3#: b(1, 3) = 11 / 24#
b(2, 0) = 3 / 2#: b(2, 1) = -2#: b(2, 2) = 7 / 6#: b(2, 3) = -1 / 4#
b(3, 0) = -1 / 6#: b(3, 1) = 1 / 4#: b(3, 2) = -1 / 6#: b(3, 3) = 1 / 24#
MatMul d(), a(), a()
MatMul c(), d(), b()
printm c()
Print
For i = 1 To 4
MatMul d(), c(), c()
MatMul c(), d(), b()
printm c()
Print
Next
Sub MatMul (ans() As Double, a() As Double, b() As Double)
Dim As Long i, j, k, n, m, p
If (UBound(a, 2) = UBound(b)) Then 'if valid dims
n = UBound(a, 2)
m = UBound(a)
p = UBound(b, 2)
For i = 0 To m
For j = 0 To p
For k = 0 To n
ans(i, j) = 0
Next k, j, i
For i = 0 To m
For j = 0 To p
For k = 0 To n
ans(i, j) = ans(i, j) + (a(i, k) * b(k, j))
Next k, j, i
Else
Print "invalid dimensions"
End If
End Sub
Sub printm (a() As Double)
Dim As Long i, j, m, p
m = UBound(a)
p = UBound(a, 2)
For i = 0 To m
For j = 0 To p
Print Using "####.##############"; a(i, j);
Next j
Print
Next i
End Sub
output
Code: (Select All) 1.00000000000000 1.00000000000000 1.00000000000000 1.00000000000000
2.00000000000011 4.00000000000000 8.00000000000011 15.99999999999997
3.00000000000091 9.00000000000000 26.99999999999955 81.00000000000000
4.00000000000000 16.00000000000000 64.00000000000182 256.00000000000000
1.00000000000631 0.99999999999397 1.00000000000310 0.99999999999937
2.00000000007003 3.99999999992497 8.00000000004081 15.99999999999153
3.00000000030832 8.99999999965075 27.00000000019281 80.99999999995953
4.00000000090040 15.99999999894135 64.00000000059481 255.99999999987494
1.00000001287511 0.99999998735953 1.00000000618997 0.99999999878051
2.00000017282946 3.99999983016824 8.00000008319284 15.99999998360744
3.00000082591305 8.99999918818139 27.00000039771248 80.99999992162930
4.00000253669350 15.99999750625284 64.00000122176243 255.99999975924175
1.00003194036101 0.99996927234497 1.00001492581766 0.99999707177334
2.00043128527955 3.99958508810619 8.00020154182073 15.99996046042222
3.00206469592649 8.99801368628778 27.00096484445567 80.99981071149432
4.00634687076126 15.99389407272611 64.00296593190251 255.99941812706993
1.07888506286064 0.92429206751581 1.03674375970633 0.99279446622859
3.06536455898004 2.97754344879331 8.49623463210287 15.90268727430023
8.10050050155542 4.10492428973066 29.37575483774754 80.53410914096605
19.67932001084409 0.95217113012768 71.30324807562465 254.56781665058406
|
|
|
Dancing Tesla Coil To Music |
Posted by: SierraKen - 08-16-2024, 05:55 AM - Forum: Programs
- Replies (4)
|
 |
Hi all,
Back in 2022 I made this with the help of Petr and probably others on this forum. It simulates a Tesla Coil that shoots lightning from a rod and the lightning dances with the music you choose. Tonight I added a file dialog box to easily be able to choose a song to play on it. I also added the ability to stop it during play to choose another song. I included an old album I created on my computer around 20 years ago in the zip file. The album has no lyrics, just electronic music.
Tell me what you think, thanks.
Edit: An improved version is on the next reply post. I removed this one.
|
|
|
Detecting color depth-16 color, 256 color, or 32 bit color |
Posted by: dano - 08-16-2024, 12:38 AM - Forum: General Discussion
- Replies (20)
|
 |
I am changing all of my libraries to be agnostic to color depth...or at least trying. I want them to automatically detect whether we are in 16 color, 256 color, or 32 bit color mode and automatically make adjustments on the fly to compensate for the colors being used, and use the proper colors.
So far so good, EXCEPT that I am having an issue with accurately detecting whether we are in 16 color, 256 color, or 32 bit color.
I cannot find this as a command for QB64. Is there an easy way to accurately detect this?
|
|
|
_KEYHIT Riddle me this??? |
Posted by: Pete - 08-15-2024, 03:40 PM - Forum: Help Me!
- Replies (5)
|
 |
Here is a modified version of the _KEYHIT Wiki example...
Code: (Select All)
DefLng A-Z
Screen _NewImage(800, 600, 8)
Cls , 1
font = _LoadFont("cyberbit.ttf", 24)
unifont = _LoadFont("cyberbit.ttf", 24, "UNICODE")
_Font font
Do
x = _KeyHit
If x And x <> oldx Then
Select Case x
Case Is > 0
Color 10
Print "Pressed "; 'positive value means key pressed
oldx = x
Case Else 'negative value means key released
Color 2
Print "Released ";
x = -x
oldx = 0
End Select
Select Case x
Case Is < 256
If x < 256 Then 'ASCII code values
Print "ASCII "; x;
If x >= 32 And x <= 255 Then Print "[" + Chr$(x) + "]" Else Print
End If
Case 256 To 65536 '2 byte key codes
Print "2-BYTE-COMBO "; x And 255; x \ 256;
x2 = x \ 256
If x2 >= 32 And x2 <= 255 Then Print "[" + Chr$(x2) + "]" Else Print
Case 100000 To 199999 'QB64 Virtual Key codes
Print "SDL VK"; x - 100000
Case Else
If x >= 200000 And x < &H40000000 Then
Print "QB64 VK"; x - 200000
_Continue
End If
If x >= &H40000000 Then 'Unicode values (IME Input mode)
Print "UNICODE "; x - &H40000000; "0x" + Hex$(x - &H40000000) + " ...";
cx = Pos(1): cy = CsrLin
_Font unifont
Locate cy, cx
Color 15
z$ = MKL$(x - &H40000000) + MKL$(0)
Print z$ + z$ + z$;
_Font font
Locate cy, 1: Print
End If
End Select
End If
Loop
Do this...
PRESS ALT.
RELEASE ALT.
So why does it record just the SDK value when alt is pressed, but records both the SDK and ASCII values when released? I'd feel better about the operation if it did not cycle back to deliver the -18 ASCII value after previously delivering the -308 SDK value when the Alt key was released.
Pete
|
|
|
|