Jump to content

Copy (control + c) when keyboard layout isn't English?


Recommended Posts

I have search but didn't find a solution. I select the filename text of a desktop icon shortcut through mouse clicks. I want to copy this text to chipboard. It works fine in English keyboard layout, but if I use Greek keyboard layout it doesn't.

I found _WinAPI_SetKeyboardLayout  ( $hWnd, $iLanguage [, $iFlags = 0] ) , but what $hWnd should I use?
Everything I tried failed.

Here is some of my code:

Local Const $english=0x0809
$hGUI=""
_WinAPI_SetKeyboardLayout ( $english, $hGUI )
MouseClick($MOUSE_CLICK_LEFT  , 743,5) ;epilego ikonidio me velaki, an einai epilegmeno idi, de doyleyei
send("{F2}")
sleep(500)
Send ("^c")
sleep(500) ;<===== Experiment with different values to get the optimum sleep time
 Local $sData = ClipGet()

Thanks!

Edited by sosimple
Link to comment
Share on other sites

I tried a different approach: Run the code 2 times. One in English keyboard layout, and one in Greek keyboard layout, so that, in every case, script to work. But every time (if default keyboard is Greek before run the script), the command  Send ("^c") DOESN'T copy, but sent a "c". (although keyboard HAS change to English , I see it in language bar, that's why I have set sleep(3000) )

Even more strange, where I have ;MsgBox(0,"", $sData ), if I delete ";" to actually use MsgBox(0,"", $sData )  then the code works as I want..

I can't understand why.. Really strange. This is the code, I have spent hours.. 

MouseClick($MOUSE_CLICK_LEFT  , 743,5) ;epilego ikonidio me velaki, an einai epilegmeno idi, de doyleyei
send("{F2}")
sleep(500)
Send ("^c")
Send ("{escape}")
sleep(500) ;<===== Experiment with different values to get the optimum sleep time

 Local $sData = ClipGet()

;*** change keyboard language and do the same one more time
Send ("{LSHIFT DOWN}")
Send ("{ALT}")
Send ("{LSHIFT UP}")


sleep(3000)
;MsgBox(0,"", $sData )

 send("{F2}")
sleep(3000)

Send ("^c")
sleep(1000) ;<===== Experiment with different values to get the optimum sleep time

 Local $sData = ClipGet()


Send ("{escape}")

MouseClick($MOUSE_CLICK_LEFT  , 743,5) ; apoepilego velaki

 

Edited by sosimple
Link to comment
Share on other sites

Desktop is in fact Listview so you can use something like this:

#include <GuiListView.au3>

$hListView = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]")
$item = _GUICtrlListView_GetNextItem($hListView) ; selected
$text = _GUICtrlListView_GetItemText($hListView, $item)

MsgBox(0, "Information", "Selected Item Text: " & $text)

 

Link to comment
Share on other sites

Maybe im looking at this totally wrong, but maybe you could just clipput?

I mean after selecting the icon, press F2 and clipput should work no?

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Instead of changing the keyboard layout, can you maybe detect the keyboard layout in HKEY_CURRENT_USER\Keyboard Layout\Preload and use a SELECT..CASE?

Then you can define what keys to send based on the layout. For my US English keyboard it seems the keyname is 1 and the value is 00000409. For Greek it might be 0001040E (http://web.archive.org/web/20171216144224/http://easydesksoftware.com/keyboard.htm)

Maybe for Greek it's Ctrl+ψ (for CTRL+C) and Ctrl+ω (for CTRL+V) (I don't have Greek keyboard).

$s_whichKey = RegRead("HKEY_CURRENT_USER\Keyboard Layout\Preload","1")

Select
    Case $s_whichKey = "00000409" ; Ingles
        Send ("^c")
    Case $s_whichKey = "0001040E" ; Griego
        Send ("^ψ")
EndSelect 

Using your first example but no switch keyboard layout:

$s_whichKey = RegRead("HKEY_CURRENT_USER\Keyboard Layout\Preload", "1")
$hGUI = ""
MouseClick($MOUSE_CLICK_LEFT, 743, 5) ;epilego ikonidio me velaki, an einai epilegmeno idi, de doyleyei
Send("{F2}")
Sleep(500)
Select
    Case $s_whichKey = "00000409" ; Ingles
        Send ("^c")
    Case $s_whichKey = "0001040E" ; Griego
        Send ("^ψ")
EndSelect
Sleep(500) ;<===== Experiment with different values to get the optimum sleep time
Local $sData = ClipGet()
Edited by ModemJunki
Add some data, change a sentence to make more sense

Always carry a towel.

Link to comment
Share on other sites

Hi. Thanks to everybody, I'll try what has been written here as soon as I found time.

I have tried this approach: Detect what is my current keyboard language .

-If it is English, run the script, everything ok

-If it is Greek, turn it to English, run the script --> Doesn't working.. 

If you see in my code I have a very long sleep (10000) just to be sure. In this time I test that everything run as I wanted.

Keyboard DOES go to English but script doesn't work as it should again.. The command  Send ("^c") doesn't actually copy, but it send a "c" I see the "c" copied in the text.. 

I think is a bug of autoitscript language or something..

Here is my code if anyone want to test by his self:

 

#Include <File.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPISys.au3>

;**** If current language is Greek, set keyboard to English 
Func GetActiveKeyboardLayout($hWnd)
    Local $aRet = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)
    $aRet = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $aRet[0])
    Return '0000' & Hex($aRet[0], 4)
 EndFunc   ;==>GetActiveKeyboardLayout


 $TrexonGlosa= GetActiveKeyboardLayout(WinGetHandle(''))
 ;MsgBox(0, "", "language:( 5 mhdenika prin 809 aglika aglias , 408 εληνικα) " & $TrexonGlosa)
if $TrexonGlosa=00000408 Then
  ; MsgBox(0, "", "language:( 5 mhdenika prin 809 aglika aglias , 408 εληνικα) " & $TrexonGlosa)
  ;***  Here I change language to English 
  Send ("{LSHIFT DOWN}")
Send ("{ALT}")
Send ("{LSHIFT UP}")

sleep(10000)


   EndIf



;** copy name

MouseClick($MOUSE_CLICK_LEFT  , 743,5) ;epilego ikonidio me velaki, an einai epilegmeno idi, de doyleyei
send("{F2}")
;ClipPut()
Send ("^c")
sleep(500) ;<===== Experiment with different values to get the optimum sleep time
 Local $sData = ClipGet()
    ; Display the data returned by ClipGet.
    ;MsgBox(0, "", "The following data is stored in the clipboard: " & @CRLF & $sData)
Send ("{escape}")
MouseClick($MOUSE_CLICK_LEFT  , 743,5) ; apoepilego velaki

 

Edited by sosimple
Link to comment
Share on other sites

2 minutes ago, FrancescoDiMuro said:

@sosimple

Mouse clicks and send hotkeys is not a dynamic way to interact with controls/GUIs.

If you are trying to do so, then look at Control* functions, and/or Win* ones :)

I know but I need the filename of a random desktop shortcut in a specific position of the screen. I suppose it must be better solution, but I don't know a better one. Even if I found a better solution for this, I still have to use mouse clicks because I need to control an external application . If it works OK with mouse clicks I would improve to in future so that to use less or no mouse clicks.

Link to comment
Share on other sites

45 minutes ago, ModemJunki said:

Did you try my suggestion, not changing the keyboard layout?

I trying it now. Very helpful. This:

Maybe for Greek it's Ctrl+ψ (for CTRL+C) and Ctrl+ω (for CTRL+V) (I don't have Greek keyboard)

Is actually exactly as you posted, and I didn't even knew it..

I think it will work.

 

Edit. Many thanks to you and all others who helped. I actually haven't found the time yet to try some ideas that has been posted. I will try some. But your post of using Ctrl+ψ , was something I didn't know although i am Greek :) All those years I turned keyboard to English for copy past :) If I knew this, I would have use it, so when you posted it and tested in keyboard that it does work I knew it will in script.

So I suppose problem is solved. It does work in script also. But not all your script.

This one:

$s_whichKey = RegRead("HKEY_CURRENT_USER\Keyboard Layout\Preload","1")

doesnt work. I had already read this solution and tested, but always return same number . Probably the start language, not the current. (I have modified to your script the numbers which in my pc are 00000408 for Greek and 00000809 for british English, but this is not the problem. It just dont work).

Anyway i have found solution for reading my current language and posted above. This does work:

Func GetActiveKeyboardLayout($hWnd)
    Local $aRet = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)
    $aRet = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $aRet[0])
    Return '0000' & Hex($aRet[0], 4)
 EndFunc   ;==>GetActiveKeyboardLayout

 $TrexonGlosa= GetActiveKeyboardLayout(WinGetHandle(''))
 ;MsgBox(0, "", "language:( 5 mhdenika prin 00000809=English , 00000408=Greek) " & $TrexonGlosa)
 
 
 
So by setting in code as you posted:
if $TrexonGlosa=00000408 Then
Send ("^ψ")
EndIf
if $TrexonGlosa=00000809 Then
Send ("^c")
EndIf
 
 
It does work.
 
I still dont understand why the method of switching to English Keyboard doesnt work, as I would find it useful in future, and i am sure i am not the only one..
 
Thanks again to all. :)
Edited by sosimple
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...