|
Post by honky on Jun 23, 2023 7:19:00 GMT
Hello, good morning, Is there a way to detect a combination of keys? Examples: "Ctrl + R"; or: "shift +p". If yes, how to do ? Thank you for...
|
|
|
Post by Rod on Jun 23, 2023 8:49:02 GMT
Inkey$ tells you what keys or combination of keys have been pressed. I always find it easier just to look see what the return is for any keypress using this routine, then coding that into my program.
'INKEY.BAS - how to use the Inkey$ variable open "Inkey$ example" for graphics as #graph #graph, "when characterInput [fetch]" #graph, "setfocus" wait
[fetch] 'a character was typed! key$ = Inkey$ if len(key$)=1 then print "Inkey$ length = ";len(key$);" "; print "ASC value = ";asc(key$);" "; print "Glyph character is ";key$ if asc(key$)=18 then notice "Ctr+r" if asc(key$)=80 then notice "Shift+p" end if if len(key$)=2 then print "Inkey$ length = ";len(key$);" "; print "First ASC value = ";asc(left$(key$,1));" "; print "Second ASC value = ";asc(right$(key$,1)) end if wait
|
|
|
Post by honky on Jun 23, 2023 9:24:44 GMT
For: "Shift + U", he returns the 2 ASC codes of: "Shift" and the Gliph: "U", it's good.
But for: "Ctrl + u", he returns the 2 ASC codes of: "Ctrl" but not the Gliph: "u". Instead, there is a little vertical rectangle
|
|
|
Post by Rod on Jun 23, 2023 11:26:35 GMT
No, you need to look for the combination (keycode) you want. Pressing u returns a one character inkey$ with asc value 117,u pressing shift+u or caplock+u returns a one character inkey$ with asc value 85,U But pressing Ctrl+u or Ctrl+U or caplock+u gets a one character inkey$ with asc value 21. 21 is the keycode assigned to Ctrl+u It is often easier to ignore two character inkey$ values the single character inkey$ has the information you need unless you specifically need to know what control keys are pressed. But you really just need the keycode. learn.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input
|
|
|
Post by honky on Jun 23, 2023 13:16:39 GMT
Ah, ok, thank you.
|
|
|
Post by honky on Jun 25, 2023 14:35:32 GMT
I put it in my program:
#w.g, "when characterInput #w.g, "setfocus" '......... [fetch]" key$ = Inkey$ if len(key$)=1 then print "Inkey$ length = ";len(key$);" "; var=asc(key$) print "Glyph character is ";key$ end if ' cls if len(key$)=2 then print "Inkey$ len = ";len(key$);" "; print "First ASC value = ";asc(left$(key$,1));" "; print "Second ASC value = ";asc(right$(key$,1)) end if select case var case 1 m$="ctrl + a ASC= ";str$(var): goto [save] ' case 2 '...ect-->26
It works well, but for a single combination, he writes twice or three times in the file. Can we do something there?
|
|
|
Post by Rod on Jun 25, 2023 15:06:15 GMT
The keyboard throws lots of key presses at you. Especially while the user presses a combination. But you only want to react to single byte messages, ignore two byte messages. React when you get one byte and it is the byte you want.
|
|
|
Post by honky on Jun 25, 2023 17:03:04 GMT
It's good, I resolved with gosubs-returns Thank you for advice.
|
|