Utility - View Raw Keystrokes

BlitzMax Forums/BlitzMax Programming/Utility - View Raw Keystrokes

dw817(Posted 2016) [#1]
So you are coding small projects and what have you, and you don't have the full list of raw keystrokes in front of you.

Want to have CTRL-Z in your program but can't remember that it's both 162 and 90 ?

Or if you are just interested in how raw keystrokes are read in BlitzMAX ?

No problem ! Run this program, let it sit in the background, and ALT-TAB to it to view these keystrokes in both decimal and hexadecimal to help you with your coding or just to educate you on the use of the function KeyDown().

Try this which is an error. Hold down the LEFT SHIFT. Without letting go, hold down the RIGHT SHIFT. Now let go of the LEFT SHIFT, then the RIGHT SHIFT. Notice that the LEFT SHIFT is stuck until you hit it again !

Try numbers (or arrows) from your keypad, then hit NUM-LOCK and try hitting the same keys again. Notice how they change values ! Pretty informative. Things that go on in the background of your code. :)






Bobysait(Posted 2016) [#2]
if you just want a really small box :

Import maxgui.drivers
Local p:TGadget=CreatePanel(0,0,0,0,CreateLabel("",0,0,20,20, CreateWindow("", 0,0,20,20,0,WINDOW_CENTER)),PANEL_ACTIVE)
Repeat;ActivateGadget p;Delay 100;If PollEvent()Then If EventID()=EVENT_KEYDOWN Then SetGadgetText p.GetGroup(),EventData()
Until EventData()=27;Delay 1000;End



dw817(Posted 2016) [#3]
Well you smart little whistle, Bobysait. :D Ok, I'll byte. Now, can you make it so it stays on top of all other screens ?

Minju, you're cheating here. You're using ; otherwise known as colon : (in other languages) to make your code appear less vertical in size by appending commands to the end of it. Here it is end to end, still small coding though:
Import maxgui.drivers
Local p:TGadget=CreatePanel(0,0,0,0,CreateLabel("",0,0,20,20,CreateWindow("",0,0,20,20,0,WINDOW_CENTER)),PANEL_ACTIVE)
Repeat
  ActivateGadget p
  Delay 100
  If PollEvent()
    If EventID()=EVENT_KEYDOWN
      SetGadgetText p.GetGroup(),EventData()
    EndIf
  EndIf
Until EventData()=27
Delay 1000
End
Still, your code is to be applauded. Very small stuff. I remember writing one-liners for Call A.P.P.L.E. years ago My key to success ? I used FOR/NEXT loops where I zeroed out the index to create an infinite loop in one line. You could do some crazy and interesting programs that way. :)


Bobysait(Posted 2016) [#4]
You can get the window on top (at least for windows OS) using SetWindowPos with HWND_TOPMOST parameter

-> you need a valid windows handle for this, you will get it with QueryGadget

Import maxgui.drivers

Local w:TGadget = CreateWindow("", 0,0,20,20,0,WINDOW_CENTER)
Local h = QueryGadget(w,QUERY_HWND) ' returns the window handle

Local p:TGadget=CreatePanel(0,0,0,0,CreateLabel("",0,0,20,20, w),PANEL_ACTIVE)
Repeat
	SetWindowPos(h, HWND_TOPMOST,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE); ' always on top (not active ... just on top)
	ActivateGadget p;
	Delay 100;
	If PollEvent()Then If EventID()=EVENT_KEYDOWN Then SetGadgetText p.GetGroup(),EventData()
Until EventData()=27;
Delay 1000;
End



ps : For "one line code", it's better to use Blitz3D
Blitzmax does not allow to add stuff after an "if".
(or I've never found how to <close> an endif on the same line)


dw817(Posted 2016) [#5]
Should be possible: Let's see ... .. ? Hmm, you're right. This doesn't work:

Let's find out why now.

Yah, nailed it. Bobysait, you cannot use a ; with an IF statement because when you do ... hmm ... easiest way to explain it is with code:
a=4
b=6

If a=5 Then a=6;b=7

Print a
Print b
If you run this, you get 4 and 6, which is correct. NOW, if you change the top to a=5 and run it, you get 6 and 7. This proves that an IF statement with a ; means you are appending the TRUE results of the IF statement, that is, it runs BOTH of these if, in this case a = 5.

Try it for yourself. That's why you can't append code to an IF statement.

I wonder about if/endif ? Let's try that.

if a=5 then a=6;b=7
If a=5 a=6;b=7
if a=5 a=6 b=7
All three of these function the same.

Very odd indeed. This doesn't even need a THEN to state what result occurs ? Not what I was trying to find but curious nonetheless. This also gets the results 6 & 7.

Well, if this is the case then ... Yeah, there's no way to have an IF/ENDIF in one line.

Does this make sense ?


dw817(Posted 2016) [#6]
BTW, forgot to add. Your Window on Top is beautiful !! I have a need for this, going to see if I can get some get old pixel graphics in there and have it stay on top.

Here are some bonus questions.

Can you read raw keystrokes in a window on top when it is not in focus ? IE, you write a program where the window stays on top out of the way, say the bottom-right-hand corner.

You are in Firefox, typing a message. Then you hit CTRL-F11 or some other interesting obscure key combination and your program that is still on top will grab that keystroke, react on it, and take over your keyboard to type something directly where you are now - in this case, Firefox entering a message.

That would definitely be interesting. I could do stuff like that in GFA years ago.


Endive(Posted 2016) [#7]
Does this make sense ?


No, none of this makes any sense at all.


BlitzSupport(Posted 2016) [#8]
No trolling, please.


dw817(Posted 2016) [#9]
Do you really not understand the IF statement or are you just trying to mess with me ? :)

He's not trolling, BlitzS (I hope). Maybe what I'm trying to explain is complex and I'm not doing a good job of it ?


Bobysait(Posted 2016) [#10]
Must admit, you're not very clear, but anyway, nice try.


you cannot use a ; with an IF statement because when you do [...]


That is a wrong statement that makes things harder to understand.
We can actually use ";" in an IF statement.
Everything after the "If" happens when the condition of "If" is True
What you probably mean was (maybe I'm wrong) :
We can't use a ";" to happen something that is not dependant of the "If" condition while on the same line after an "If"

What you maybe don't know (and that's the main reason, at the beginning, I was having trouble with the Blitzmax's "If" syntax), it's that blitz3d allows to enclose an If with a Endif and continue on the line regardless of the "If".

If x=3 : a=8 : Endif : x=2

This is a blitz3d code, "x = 2" will always be computed whatever the result of "If x=3"
Blitzmax does not allow to do this.

if(x==3){a=8;};x=2;

In C, this will produce the same result as the blitz3d code.

While Blitzmax will just generate an error if you do :
If (x=3) a=8; endif; x=2
or 
if (x=3) then a=8; x=2
or
if (x=3) then a=8;endif; x=2
or
if (x=3); then a=8; x=2
or
if (x=3); then a=8;Endif; x=2

In every case it just produice an error saying there is a missing If.
There is maybe a syntax to do this, but I don't know it.

There is probably just no legit reason for this except it's been made this way.
That's probably the reason it's hard to explain, it's just because there is nothing to explain other than : It's written to be like this.
And it's maybe a matter of counting the EOL character or not to validate an If/Endif expression. Here it seems Blitzmax needs a EOL to accept it.


dw817(Posted 2016) [#11]
Well, what I mean to say is not so much you CAN'T use ; in an IF statement, just be aware it will link all the statements together IF the condition reads true. That's all.

This:

if a=5 then b=6 ; b=7

Will mean that b will equal 6 AND b will equal 7 ONLY WHEN a=5

Any idea on how to read keystrokes if the task is not active ? We're on a roll and I wanted to keep the flow going. :)


Endive(Posted 2016) [#12]
dw, I just didn't understand the point of the program and now I do. Personally I haven't ever needed this. But someone might... someday...

I think that what people are trying to communicate to you is the fact that Blitzmax is sort of a dead language-- or at the very least VERY close.

Here is the trend graph for interest in Blitzmax:

https://www.google.com/trends/explore#q=blitzmax

Ask yourself how much effort you want to put into teaching material on that trend graph, when the overwhelming majority of current users and forumites seem to be very experienced programmers.

On the other hand, perhaps you could start a series of videos and a blog for teaching game programming and general beginning programming, using Blitz as the language.

Maybe you could generate some new interest in the language over time. When things are released as opensource they seem to get lives of their own and if you can bring new programmers into the language it will certainly help it continue to grow.

Do you want to be an evangelist to beginners on an opensource programming language? I think if you put in work on promoting it you could get up to around 10000-20000 views per video and that would certainly promote the language to a huge extent.

I should really apologize for getting so irritable with you, I am pretty crabby normally and I was seriously very ill for a week and a half, I had a fever and was smothering in snot the consistency of road tar. Just don't get testy and sarcastic when other people are trying to help you or communicate with you, that was legitimately irritating under any circumstance.


Brucey(Posted 2016) [#13]
I think that what people are trying to communicate to you is the fact that Blitzmax is sort of a dead language

Eh?


Endive(Posted 2016) [#14]
Brucey, look at the trend line. Am I wrong? How many people actually still use this product? *I* certainly love it, it's easily my favorite language of all time.

What are we going to do about that trend line? Maybe evangelizing it to beginning game programmers would actually be a very good plan, perhaps the best bet for survival into the future.

I'd be willing to help with that.


Brucey(Posted 2016) [#15]
I'm sure there are a lot of people using BlitzMax.

But this thread probably isn't the place to discuss it...


Endive(Posted 2016) [#16]
Ok, I'll make a new thread.


Bobysait(Posted 2016) [#17]

Any idea on how to read keystrokes if the task is not active ?



Well ... with windows APIs you can catch keys events ... (and make a keylogger hum) but, to be honest, I hate coding with windows API.

You should find some doc on msdn regarding some functions like PeekMessage (Blitzmax use the PeekMessageW function as far as I remember)
But you 'll need a proper MSG structur to handle messages. You can create it with a Blitzmax Type like this :
type MSG
  field hwnd:Int;
  field message:Int; ' supposed to be an Unsigned Int
  field wParam:Int;
  field lParam:Short;
  field time:Int;
  'POINT;
  field x:Int;
  field y:Int;
end type
local l_msg:MSG = new MSG;

just pass the l_msg to the function, then read l_msg.message to parse the data (WM_KEYDOWN/WM_KEYUP should give similar things as EVENT_KEYDOWN/EVENT_KEYUP)

But, there will probably be some issues due to the blitzmax window that already catch events and remove them from windows queue.


Brucey(Posted 2016) [#18]
In the real world, hwnd is a pointer (as is wParam and lParam).
And I'm pretty sure lParam isn't a 16-bit Short. It's *at least* Int size on 32-bit architectures...

fyi :-)


dw817(Posted 2016) [#19]
This is only to address the suggestion that BlitzMAX is on the decline. Well guys, as my tagline says, I'm always wandering (and often wondering for that matter too).

What programming language do you think would be best to write a RPG Maker in where you can both load and save world files Online ?

Bear in mind the language needs to have the ability to:
1. Load and save images, media, and data files (Online if need be)
2. Play WAVs and OGGs (Mid, WMA, and Mp3 bonus)
3. Read mouse & keyboard
4. Works on multiple platforms, Windows, Macintosh, Cellphones
5. Load and view, work, and download webpages (BlitzMAX does this)
6. Virtual Screens (Casaber's code does this)
7. Can display 640x480 random color pixels no slower than 30fps
8. No 'staggering' if played Online, like HTML5 does with Monkey-X

... Think that's about it. So far BlitzMAX can do 1 (for offline), 2, 3, 4 (maybe not cellphones), 5, 6, 7, not 8.

For instance, Blitz3D or BlitzPlus which seem to have a different popularity, can either of those languages do what I described above ?


Bobysait(Posted 2016) [#20]
@dw817 :
You're off topic on your own topic.

@brucey :

In the real world, hwnd is a pointer (as is wParam and lParam).
And I'm pretty sure lParam isn't a 16-bit Short. It's *at least* Int size on 32-bit architectures...



I inverted the w and l params
WParam in old architecture was a "WORD param" (unsigned 16 bits short) and L stand for the "Long Param"
I didn't update my knowledges about thoose stuff for a while.
I suppose the 64 arch use both 64 bits for W and L params ...

As I said, I really hate the windows API stuff :/


dw817(Posted 2016) [#21]
Yeah, no kidding, Boby. *Grin* That's fine. I think I'll stick with BlitzMAX. It is a very good programming language. In fact - I may have something interesting to show fairly soon. (working on it).