Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

keyup/keydown with usb library

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Scadi

Bascom Member



Joined: 29 Apr 2011
Posts: 8

PostPosted: Thu May 05, 2011 1:53 am    Post subject: keyup/keydown with usb library Reply with quote

Hi,
I bought the USB Library and the hid_keyboard-162.bas works fine.
However, I have a problem with a program that some key codes sometimes do not recognize.
Only when the key code repeatedly sends, it is detected. With PS/2 I have the same problem that I can deal with a short break between make and break.
My guess is now the USB Library keydown / keyub quickly fired.
Is there a way keydown and send keyub separately? This would clearly be useful because some programs (including Windows) expect a first pressed key (eg alt + tab or ctrl + tab). Other programs expect e.g. a pressed key in combination with a mouse click, etc.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5024
Location: Holland

blank.gif
PostPosted: Thu May 05, 2011 9:21 am    Post subject: Reply with quote

You mean an external program you run, does not recognize the keys sent ?
The group of 8 bytes sent are 1 keypress.
When the first one uses a modifier like HID_MODIFIER_LEFT_CTRL
you can then send a group with also CTRL and later you use NONE when CTRL is supposed to be released.

Const HID_MODIFIER_NONE=0
Const HID_MODIFIER_LEFT_CTRL=1
Const HID_MODIFIER_LEFT_SHIFT=2
Const HID_MODIFIER_LEFT_ALT=4
Const HID_MODIFIER_LEFT_GUI=8
Const HID_MODIFIER_RIGHT_CTRL=&H10
Const HID_MODIFIER_RIGHT_SHIFT=&H20
Const HID_MODIFIER_RIGHT_ALT=&H40
Const HID_MODIFIER_RIGHT_GUI=&H80

_________________
Mark
Back to top
View user's profile Visit poster's website
Scadi

Bascom Member



Joined: 29 Apr 2011
Posts: 8

PostPosted: Thu May 05, 2011 1:39 pm    Post subject: Reply with quote

Hi,
my problem is not alt/shift/ctrl special each character.
If I for example a "3" send, then it is not always recognized. Only when I have the "3" 5-10 times they send is detected (but also several times).
Is it possible to make next?
keydown "3"
Waitms 50
keyup "3"
Back to top
View user's profile
radan

Bascom Member



Joined: 06 Jan 2007
Posts: 35

ukraine.gif
PostPosted: Thu May 05, 2011 2:10 pm    Post subject: Reply with quote

http://bascom.at.ua/publ/atomnaja_klaviatura_vinduksoida_hid_usb/1-1-0-54
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5024
Location: Holland

blank.gif
PostPosted: Thu May 05, 2011 8:16 pm    Post subject: Reply with quote

each key you sent, must be detected.
try it with notepad to see if you get all keys.
Keys sent with usb can not get lost.

The usb keyboard does not work with make/break.
If you keep a key pressed in PS2, you get repeated keys.

You first need to find out if the problem is that sending key data does not work(by sending them to notepad)
Or that the app you try to send it to, does not respond to them.

Did you try to send
instead of :
Uedatx = Usb_key ' Byte2: Keycode 0
Uedatx = 0 ' Byte2: Keycode 1

This :
Uedatx = Usb_key ' Byte2: Keycode 0
Uedatx = Usb_key ' Byte2: Keycode 1

_________________
Mark
Back to top
View user's profile Visit poster's website
Scadi

Bascom Member



Joined: 29 Apr 2011
Posts: 8

PostPosted: Thu May 05, 2011 8:30 pm    Post subject: Reply with quote

I managed it;-)
Code:
If Key_hit = 1 Then                                     'wait for the data
       Transmit_no_key = 1
       Uenum = Ep_kbd_in
       Uedatx = 0                                           '  Byte0: Modifier use this to send shift,ctrl and alt keys
       Uedatx = 0                                           '  Byte1: Reserved
       Uedatx = Usb_key                                     '  Byte2: Keycode 0
       Uedatx = 0                                           '  Byte2: Keycode 1
       Uedatx = 0                                           '  Byte2: Keycode 2
       Uedatx = 0                                           '  Byte2: Keycode 3
       Uedatx = 0                                           '  Byte2: Keycode 4
       Uedatx = 0                                           '  Byte2: Keycode 5
       Usb_ack_in_ready
       Exit Sub
    End If

    If Transmit_no_key = 1 Then                             ' if this flag was set
      Key_hit = 1                                           'make it one so we can send the next key after we are done sending 0
      Transmit_no_key = 0
      Uenum = Ep_kbd_in
      Uedatx = 0
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Waitms 100
      Usb_ack_in_ready
    End If


New is the Waitms 100 before the second Usb_ack_in_ready.

I have another question.
Is it possible to convert the hid_keyboard-162.bas you can also send data from PC> microprocessor?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5024
Location: Holland

blank.gif
PostPosted: Thu May 05, 2011 9:21 pm    Post subject: Reply with quote

That should be possible by adding an endpoint.
I do not know if the keyboard can receive data from PC. I think so because of the leds so simplest would be to add a keyboard out endpoint.

Otherwise, it will be more complex : you create 2 devices then for example keyboard and generic hid. but this will require 2 reports too.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum