noobieautolearn Posted July 6, 2015 Posted July 6, 2015 (edited) I was looking to see if there is a command to check and see if the clipboard has any digits on it (0-9) and then do something if it does, like paste that value somewhere and if it doesn't follow other directions.For example if I copy "char1yak" it would see the 1 and do something, however if I copy "chartmain" it would see that all the characters are letters and do something else. Edited July 7, 2015 by noobieautolearn
aleph01 Posted July 7, 2015 Posted July 7, 2015 See ClipGet ( ) in the help File. @error tells you if you have text instead of numbers. You may have to play around to see how alpha-numeric data is handled._aleph_ Meds. They're not just for breakfast anymore.
noobieautolearn Posted July 7, 2015 Author Posted July 7, 2015 See ClipGet ( ) in the help File. @error tells you if you have text instead of numbers. You may have to play around to see how alpha-numeric data is handled._aleph_ I checked it out, with clipget it will set error messages as follows. 1 if there is no text which doesn't help me. 2 If there is a non text entry, for example if you use print screen to take a picture. However it see's numbers and letters or any combination as text. To 3 or 4 if it can't access the clipboard which does not apply.
drquochoai Posted July 7, 2015 Posted July 7, 2015 (edited) ;You can use Number Func ConsoleWrite(Number("65")&@CRLF) ; result 65 ConsoleWrite(Number("56time54")&@CRLF) ; result 56 ConsoleWrite(Number("time")&@CRLF) ; result 0 for not begining of number ConsoleWrite(Number("5.45646")&@CRLF) ; result 5.45646 ConsoleWrite(Number("4,45646")&@CRLF) ; result 4 because "," is not a number ; For clipboard you can call function Number() of ClipGet() ConsoleWrite( Number(ClipGet()) ) ;If just want to check if it's a number or not, you can use IsNumber() of ClipGet() ConsoleWrite( IsNumber(ClipGet()) ); 1- for yes ; 0- for noThe Number function will return the number begin the text until he is not a text. Edited July 7, 2015 by drquochoai
noobieautolearn Posted July 7, 2015 Author Posted July 7, 2015 (edited) ;You can use Number Func ConsoleWrite(Number("65")&@CRLF) ; result 65 ConsoleWrite(Number("56time54")&@CRLF) ; result 56 ConsoleWrite(Number("time")&@CRLF) ; result 0 for not begining of number ConsoleWrite(Number("5.45646")&@CRLF) ; result 5.45646 ConsoleWrite(Number("4,45646")&@CRLF) ; result 4 because "," is not a number ; For clipboard you can call function Number() of ClipGet() ConsoleWrite( Number(ClipGet()) ) ;If just want to check if it's a number or not, you can use IsNumber() of ClipGet() ConsoleWrite( IsNumber(ClipGet()) ); 1- for yes ; 0- for noThe Number function will return the number begin the text until he is not a text.This may be helpful, I was also looking at IsInt. One thing that is confusing me is it says Return ValueSuccess:Returns 1.Failure:Returns 0 if expression is not integer. From what I can tell it is not returning an @error 1 or 0 so what code would be able to see if it returned 1 or a 0? If it was @error you could write something like If @error = 0 Then MsgBox(16, "not an integer","meh".) Since it says it just returns a 1 or a 0 what would your code have to look like? Edited July 7, 2015 by noobieautolearn
Malkey Posted July 7, 2015 Posted July 7, 2015 @drquochoaiConsoleWrite(Number("char1yak") & @CRLF) ; result 0 for not beginning with number. The number "1" in "char1yak" is not detected. (See opening post) Here is another attempt to solve your problem.Local $CB, $CBOld = "", $iMsg While 1 $CB = ClipGet() If $CBOld <> $CB And StringRegExp($CB, ".+") Then If StringRegExp($CB, "\d") Then $iMsg = MsgBox(1, "Result", "Number present on clipboard" & @CRLF & @CRLF & 'Press "Cancel"to exit') $CBOld = $CB Else $iMsg = MsgBox(1, "Result", "No Numbers on clipboard" & @CRLF & @CRLF & 'Press "Cancel"to exit') $CBOld = $CB EndIf If $iMsg = 2 Then Exit EndIf Sleep(150) WEnd
jguinch Posted July 7, 2015 Posted July 7, 2015 (edited) A good way could be to use _ClipBoard_SetViewer and then avoid some repetition of ClipGet().expandcollapse popup#include <Clipboard.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> Global $hGUI = GUICreate("myGui") Global $vClipBoardContent $g_hNext = _ClipBoard_SetViewer($hGUI) GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN") GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD") While 1 Sleep(100) $iMsg = GUIGetMsg() If $iMsg = $GUI_EVENT_CLOSE Then ExitLoop WEnd _ClipBoard_ChangeChain($hGUI, $g_hNext) Func WM_CHANGECBCHAIN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg If $wParam = $g_hNext Then $g_hNext = $lParam ElseIf $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_CHANGECBCHAIN, $wParam, $lParam, 0, "hwnd", "hwnd") EndIf EndFunc ;==>WM_CHANGECBCHAIN Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $vClipBoard = _ClipBoard_GetData() If $vClipBoard <> $vClipBoardContent Then If StringRegExp($vClipBoard, "\d") Then MsgBox(0, "", "Number present on clipboard") EndIf EndIf If $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_DRAWCLIPBOARD, $wParam, $lParam) EndFunc ;==>WM_DRAWCLIPBOARD Edited July 7, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
noobieautolearn Posted July 7, 2015 Author Posted July 7, 2015 (edited) Here is another attempt to solve your problem.Local $CB, $CBOld = "", $iMsg While 1 $CB = ClipGet() If $CBOld <> $CB And StringRegExp($CB, ".+") Then If StringRegExp($CB, "\d") Then $iMsg = MsgBox(1, "Result", "Number present on clipboard" & @CRLF & @CRLF & 'Press "Cancel"to exit') $CBOld = $CB Else $iMsg = MsgBox(1, "Result", "No Numbers on clipboard" & @CRLF & @CRLF & 'Press "Cancel"to exit') $CBOld = $CB EndIf If $iMsg = 2 Then Exit EndIf Sleep(150) WEndThank you for posting this code, I have a couple of questions for this code.For "Local $CB, $CBOld = "", $iMsg" is that just setting both $CB and $CBOld to blank, $iMsg?For "$CBOld <> $CB And StringRegExp($CB, ".+")" is that just saying if $CBOld is less than or greater than $CB and StringRegExp($CB, ".+") then do the below? Edited July 7, 2015 by noobieautolearn
Malkey Posted July 7, 2015 Posted July 7, 2015 (edited) ....For "Local $CB, $CBOld = "", $iMsg" is that just setting both $CB and $CBOld to blank, $iMsg?...."Note: In AutoIt you can create a variable simply by assigning a value ($myvar = 0) but many people like to explicitly declare them." This quote is from AutoIt help file > Local (Keyword reference) > Remarks. I like to explicitly declare variables, sometimes.Also the first time through the script, "$CBOld" is compared to a string from the clipboard in the conditional expression of an "If" statement. So I thought "$CBOld" should contain something - an empty string. ....For "$CBOld <> $CB And StringRegExp($CB, ".+")" is that just saying if $CBOld is less than or greater than $CB and StringRegExp($CB, ".+") then do the below? "<>" means not equal to."StringRegExp($CB, ".+")" was added as another conditional expression in the "If" statement to specify only characters are permissible. Without this StringRegExp function, pressing the print screen button would activate the examine contents of clipboard "If...Then...Else...EndIf" statement. I am not completely certain why this StringRegExp function excludes an image on clipboard, but it does. Edited July 7, 2015 by Malkey
Alexxander Posted July 7, 2015 Posted July 7, 2015 (edited) here is my modest code in case you don't understand regex (like me)$var = clipget() if StringInStr($var,"1") or StringInStr($var,"2") or StringInStr($var,"3") then;and so on msgbox(0,0,"the clipboard have one or more numbers") else msgbox(0,0,"the clipboard does not contain any numbers") endifor using a for loop $var = clipget() for $i = 0 to 9 then if StringInStr($var,$i) then msgbox(0,0,"the clipboard have one or more numbers") exitloop else if $i = 9 then msgbox(0,0,"the clipboard does not contain any numbers") endif next i did not tested this code i'm not working on windows os right now , but it should work fine ... Edited July 7, 2015 by Alexxander
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now