Jump to content

Which key is pressed


Recommended Posts

I need to record keystrokes of two keys "q" and "w"

However since the majority of people using my script are russian, they have russian keyboard layout and the russian letter corresponding to q and w are "й" and "ц". I need to differentiate between the russian and english keys. However I can't think of a way to do this. This is what i've got so far.

Any suggestions?

Case _IsPressed("51", $hDLL)
   If _IsPressed("A0", $hDLL) or _IsPressed("A1", $hDLL) Then
      $send = "Q"
   Else
      $send = "q"
   EndIf
   Pressed ($send)
   While _IsPressed("51", $hDLL)
      Sleep (10)
   Wend
Case _IsPressed("57", $hDLL)
   If _IsPressed("A0", $hDLL) or _IsPressed("A1", $hDLL) Then
      $send = "W"
   Else
      $send = "w"
   EndIf
   Pressed ($send)
   While _IsPressed("57", $hDLL)
      Sleep (10)
   Wend
Edited by tsolrm
Link to comment
Share on other sites

  • Moderators

tsolrm,

You might use the code here to detect which keyboard language is in use - then you can adjust the code accordingly. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I've tried this and it doesn't work. Usually returns the default keyboard layout. Tried using the macro too.

#RequireAdmin
HotKeySet ("{q}", "key")
TraySetState()
$exit = TrayCreateItem("Выход")
While 1
$msg=TrayGetMsg()
If $msg = $exit Then Exit
$hWnd = WinGetHandle ("")
$layout= _GetKeyboardLayout($hWnd)
Wend
Func key ()
MsgBox (0, "test", $layout)
EndFunc
Func _GetKeyboardLayout($hWnd)
    Local $ret = DllCall("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0)
          $ret = DllCall("user32.dll", "long", "GetKeyboardLayout", "long", $ret[0])
          Return "0000" & Hex($ret[0], 4)
EndFunc
Link to comment
Share on other sites

Hey maybe THis KeyHook will help you out

The Function will both trigger in KeyUp and KeyDown events

Code

<snip>

Edited by Melba23
Code removed

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

  • Moderators

PhoenixXL,

Please read this - what you posted was essentially a full keyboard watcher. ;)

All,

We are serious about this - do NOT post scripts which watch the keyboard or try to detect virtually all the keys. Looking for a few keys such as the OP is trying to do is fine, do not drag the thread into forbidden waters. I did not post the announcement to which I linked to increase my post count and if people keep ignoring our prohibition on keyloggers then they will find they get some time off to read the rules more carefully. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Lookup the example script in the help file for <snip>

I hope thats ok @Melba

Edited by Melba23
Removed text
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

  • Moderators

qsek,

I hope thats ok @Melba

No.

All,

For the last time: In this forum you do not post, link to or name any code which watches the keyboard and returns keycodes. How difficult is that to understand? :)

We all know that there are several ways to do it - and anyone intelligent enough can work it out from first principles without too much difficulty. What we do not want you to do is to give out freebie code to every teenage "script kiddie" out there who wants to hack into his sister's e-mails - or worse.

Just use some commonsense - we do not have many prohibitions here but those we do have, we enforce. And a warning - I am now getting near the limit of my patience on this subject. ;)

M23

Edit:

tsolrm,

Sorry your thread has got so off-topic - did the code I posted above not work to get the keyboard language? :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I've tried this and it doesn't work. Usually returns the default keyboard layout. Tried using the macro too.

This code returns the active keyboard layout number.

It works for me

407 for german layout

419 кгыышфт lol

try this code, if i use the message box then windows switches to standard layout.

Console Write is safer

Func key()
ConsoleWrite($layout & @CRLF)
EndFunc   ;==>key
Edited by qsek
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

@M23

Sorry For That Post.............

I thought that It will since not log all The Keys , It may not be Refered a Keylogger...........

Anyways It wont be Repeated Again.......

Sorry For the Inconveniance

Regards

Phoenix XL

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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...