Sendkeys "Enter" and Citrix

ebbrey

Board Regular
Joined
Oct 16, 2010
Messages
56
Hello!

I'm currently lost and looking for some help with my code. I have searched the net for a couple days without luck. Hopefully i missed something and this is still possible.

Code:
Sub pleasework()
    
    Dim keys As String
    Dim wss As Object
    Set wss = CreateObject("WScript.Shell")
    AppActivate "Order"
    Application.Wait Now() + TimeValue("00:00:02")
    wss.SendKeys ("2207062")
    Application.Wait Now() + TimeValue("00:00:01")
    'wss.SendKeys ("~")
    'wss.SendKeys chr(13)
    wss.SendKeys ("{ENTER}")
    Application.Wait Now() + TimeValue("00:00:01")
    wss.SendKeys ("1")
    Application.Wait Now() + TimeValue("00:00:01")
    'wss.SendKeys ("~")
    'wss.SendKeys chr(13)
    wss.SendKeys ("{ENTER}")
    Set wss = Nothing
        
End Sub

This works perfectly in Notepad if i change AppActivate. Even as it is, it finds the correct order window remotely connected trough citrix. Starts inserting the item number.. But "enter" wont work. I have tried with wss.SendKeys ("~") / wss.SendKeys chr(13). If i press enter on my keyboard, the Citrix application recognizes the key and shifts over to quantity. (any way to get VBA to produce a "local keypress" ? :P)

What i have made is an excel sheet with all gods i usually order. I select how many of each, copy to one truncated list with a macro. Where Column B2 and down are the item number and A2 and down (until no more items to be ordered at that time) are the item quantity number. The order program trough citrix switches between item number and quantity with a single enter stroke, and then enter to get to the next item number. The next step if i would get "enter" to work with the citrix program, would be to get this to loop trough the order list from my excel sheet.

Thank you in advance. If i get this to work, it will save me 20 minutes a day :)
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
The bad news is, it might not work.

Like you, I tried for a while to get Citrix to respond but it does not expose its elements to the remote application.
 
Upvote 0
Thanks alot for your replies.. Some applications on my citrix platform will accept the enter and tab keys. But not the most imoportant one.

The ScanCodes project semes to be what i need. Just a bit heavy for my level. But eager enough to get started and try it out :)

Have a nice day!
 
Upvote 0
Whoa! I got it working :D Since im no programmer and practicly copy pasted all the code i could find regarding this topic.. Nearly giving up after 10 hours :P It works!!!! I found some code that was used for ScreenCapture and basicly just changed everything to Return. There might be something fundemental wrong with my code, but im happy!

Code:
Option Explicit


Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Const VK_RETURN = &HD
Private Const KEYEVENTF_KEYUP = &H2



Sub pleasework5()
    
    Dim keys As String
    Dim wsh As Object
    Dim mvk As Double
       
    Set wsh = CreateObject("WScript.Shell")
    mvk = MapVirtualKey(VK_RETURN, 0)
    AppActivate "Order"
    Application.ActiveWindow.Activate
    Application.Wait Now() + TimeValue("00:00:02")
    wsh.SendKeys ("2207062")
    
    Application.Wait Now() + TimeValue("00:00:02")
    keybd_event VK_RETURN, mvk, 0, 0
    keybd_event VK_RETURN, 0, 0, 0
    keybd_event VK_RETURN, 0, KEYEVENTF_KEYUP, 0
    Application.Wait Now() + TimeValue("00:00:01")
    
    wsh.SendKeys ("1")
    
    Application.Wait Now() + TimeValue("00:00:01")
    keybd_event VK_RETURN, mvk, 0, 0
    keybd_event VK_RETURN, 0, 0, 0
    keybd_event VK_RETURN, mvk, KEYEVENTF_KEYUP, 0
    Application.Wait Now() + TimeValue("00:00:01")
    Set wsh = Nothing
        
End Sub
 
Last edited:
Upvote 0
Well done.

I hadn't heard of the keybd_event function of the API but while it appears to be deprecated by SendInput (in the API) and SendKeys (generally in VB) it may be more stable when sending Control Codes to some applications (I think you've proved it is with Citrix :) ).
 
Upvote 0
Well done.

I hadn't heard of the keybd_event function of the API but while it appears to be deprecated by SendInput (in the API) and SendKeys (generally in VB) it may be more stable when sending Control Codes to some applications (I think you've proved it is with Citrix :) ).

Thanks alot :) I figured out the rest, and i can now process orders from my local machine to Citrix :D really fast

Can't believe i have punched this manually for 5 years.
 
Last edited:
Upvote 0
Pain and frustration can be great motivators, once they drive you to breaking point :).
 
Upvote 0
Whoa! I got it working :D Since im no programmer and practicly copy pasted all the code i could find regarding this topic.. Nearly giving up after 10 hours :P It works!!!! I found some code that was used for ScreenCapture and basicly just changed everything to Return. There might be something fundemental wrong with my code, but im happy!

Code:
Option Explicit


Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Const VK_RETURN = &HD
Private Const KEYEVENTF_KEYUP = &H2



Sub pleasework5()
    
    Dim keys As String
    Dim wsh As Object
    Dim mvk As Double
       
    Set wsh = CreateObject("WScript.Shell")
    mvk = MapVirtualKey(VK_RETURN, 0)
    AppActivate "Order"
    Application.ActiveWindow.Activate
    Application.Wait Now() + TimeValue("00:00:02")
    wsh.SendKeys ("2207062")
    
    Application.Wait Now() + TimeValue("00:00:02")
    keybd_event VK_RETURN, mvk, 0, 0
    keybd_event VK_RETURN, 0, 0, 0
    keybd_event VK_RETURN, 0, KEYEVENTF_KEYUP, 0
    Application.Wait Now() + TimeValue("00:00:01")
    
    wsh.SendKeys ("1")
    
    Application.Wait Now() + TimeValue("00:00:01")
    keybd_event VK_RETURN, mvk, 0, 0
    keybd_event VK_RETURN, 0, 0, 0
    keybd_event VK_RETURN, mvk, KEYEVENTF_KEYUP, 0
    Application.Wait Now() + TimeValue("00:00:01")
    Set wsh = Nothing
        
End Sub

Hello,

I am wondering if you can help me out. I have multiple sessions of Citrix open and running, and when I spend too much time working in one, the others time out. I don't have server access to these sessions, so I am trying to find a way to send a keystroke or mouse click to each of these sessions. Does the above script work for that? I typically have 9-11 sessions open. Ideally I could have a script running that sent a keystorke to each citrix connection every 5 mins or something.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,216,587
Messages
6,131,586
Members
449,657
Latest member
Timber5

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top